1.2.1 • Published 7 years ago

sails-hook-mongoindexes v1.2.1

Weekly downloads
11
License
MIT
Repository
github
Last release
7 years ago

sails-hook-mongoindexes

NPM Version NPM Downloads Build Status Code Climate Issue Count bitHound Overall Score bitHound Dependencies bitHound Dev Dependencies bitHound Code

Hook for sails and mongoDB

About

This hook allows us to write indexes for mongoDB

NPM

Use

Install

npm install sails-hook-mongoindexes

In config/connections.js

module.exports.connections = {
  somethingMongodbServer:{
    //You need sails-mongo adapter to work
    adapter: 'sails-mongo',
    host: 'localhost',
    port: 27017,
    // user: 'username',
    // password: 'password',
    database: 'test'
  },
  //You can configure multiple databases with the same format
  othermongoDBServer:{}
}

In config/models.js

module.exports.models = {
  connection: 'somethingMongodbServer',
  migrate: 'safe'
};

In models, example User.js

module.exports = {
  //Put names on your fields
  atributes:{
    name: 'string',
    lastName: 'string',
    userName: 'string',
    password: 'string',    
  },
  //And here your indexes for that fields
  index: [
    {
      //Now you can index unique fields
      ind:{userName:1},
      ops: {
        unique: true,
        required: true,
      }
    },
    {
      //Agruop fields
      ind:{name:1, lastName:1},
      ops: {
        unique: true,
        w:1
      }
    },
    {
      //Or simply required
      ind:{password:1},
      ops: {
        required: true,
        w:1
      }
    }
  ]
};

Thats all!

1.2.1

7 years ago

1.1.2

8 years ago

1.1.1

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago

0.3.1

8 years ago