vadimdemedes / mongorito

🍹 MongoDB ODM for Node.js apps based on Redux
1.38k stars 90 forks source link

support for hashed indexes, and compound indexes #212

Open devendrapratap02 opened 6 years ago

devendrapratap02 commented 6 years ago

Hi, in this issues, https://github.com/vadimdemedes/mongorito/issues/9#issuecomment-71807246

How can I create hashed index, and compound indexes in models.

An example would be great.

Thanks

vadimdemedes commented 6 years ago

Don't know to be honest, never used them. If you were able to find a solution or know what needs to be done in order to support this, feel free to reply here with your findings or submit a PR.

ambrons commented 5 years ago

I know this is nearly a year old, but figured I'd put my thoughts here. Hopefully if my understanding is wrong someone will correct me.

Digging through the code that createIndex method of the Model class uses redux-like dispatch (as the project states) which is processed by the create-index middleware. This in turns uses the call middleware which at a high level is the connection to the mongo driver. So in short reading the documentation for the mongo-native-driver for createIndex You should be able to do the following for a compound index

Post.createIndex({fielda:1, fieldb:1}, {unique: true});