Basic Mongoose Service Provider for Adonis 4.0
Basically from the old npm package used for Adonis 3.^
Installation
- Ultra instinct mode on
$ npm install adonis-4-mongoose --save
-
Update the
.env
file with your mongo credentials.defining
MONGO_URL
will exclude the remaining credentials
MONGO_HOST=localhostMONGO_PORT=27017MONGO_USER=yoursupersaiyanusernameMONGO_PASS=yoursuperawesomepassMONGO_DATABASE=yourultrainstinctdbMONGO_URL=mongo://supersaiyan.co:777/babidb (optional)
- Add config file
config/mongo.js
to your project
const Env = moduleexports = url: Env host: Env port: Env user: Env pass: Env db: Env
- Update
start/app.js
add the mongoose service provider
const providers = ... 'adonis-4-mongoose/provider/Mongoose' const aliases = ... Mongoose: 'Adonis/Addons/AdonisMongoose'
Basic Usage
Add/Update your user model app/Models/User.js
'use strict' const mongoose = const ObjectId = mongooseSchemaTypesObjectIdconst Mixed = mongooseSchemaTypesMixed let userSchema = mongoose moduleexports = mongoose
Use basic mongoose query app/Controllers/Http/UserController.js
'use strict' const User = async { let users = await User response } moduleexports = UserController