Skip to content
This repository has been archived by the owner on May 18, 2020. It is now read-only.

mayur-padshala/adonis-mongoose

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

adonis-mongoose

AdonisJS Addon Provider for Mongoose ODM (mongodb package for nodejs)

Installation

$ npm install adonis-mongoose --save

The command above will install the package mongoose too.

You need to create a config/mongo.js file with the contents:

'use strict'

const Env = use('Env')

module.exports = {
  host: Env.get('MONGO_HOST', 'localhost'),
  port: Env.get('MONGO_PORT', '27017'),
  user: Env.get('MONGO_USER', ''),
  pass: Env.get('MONGO_PASS', ''),
  db: Env.get('MONGO_DATABASE', 'adonisjs')
}

You are using a connection local without user and pass, leave it blank like on the example.

Add the entry adonis-mongoose/providers/MongooseProvider.js to the providers array on bootstrap/app.js like this:

const providers = [
  'adonis-framework/providers/ConfigProvider',
  'adonis-framework/providers/EnvProvider',
   //..OTHER DEFAULT PROVIDERS...//
  'adonis-middleware/providers/AppMiddlewareProvider',
  'adonis-auth/providers/AuthManagerProvider',
  'adonis-mongoose/providers/MongooseProvider' //add this line after install the package
]

Add the entry Mongoose: 'Adonis/Addons/AdonisMongoose' on the aliases object on bootstrap/app.js file like this:

const aliases = {
  Command: 'Adonis/Src/Command',
  Config: 'Adonis/Src/Config',
   //..OTHER DEFAULT PROVIDERS...//
  View: 'Adonis/Src/View',
  Mongoose: 'Adonis/Addons/AdonisMongoose' //this line
}

Usage

Now you can use mongoose anywhere in the application like below

app/Model/Post.js

'use strict'

/**
*  @var Mongoose mongoose
*/
const mongoose = use('Mongoose')

let postSchema = mongoose.Schema({
    author: ObjectId,
    title: String,
    published: {
        type: Date,
        default: Date.now
    }
});

module.exports = mongoose.model('Post', postSchema)

As you can see, it's very easy to use. The provider is just a wrapper of awesome mongoosejs library.


How to use Mongoose stuff?

Found any Bugs?

Before opening an Issue on this repository, check if it's not a bug on Mongoose package here: https://github.com/Automattic/mongoose/issues

License

Adonis-Mongoose is released under the MIT License.

About

AdonisJS Addon Provider for Mongoose ODM

Resources

License

Stars

Watchers

Forks

Packages

No packages published