Partial indices in mongodb / mongoose

In the sparse index documentation, I found a note on mongodb 3.2 partial indexes

Changed in version 3.2: Starting with MongoDB 3.2, MongoDB provides the ability to create partial indexes. Partial indexes offer an extended set of sparse index functionality. If you are using MongoDB 3.2 or later, partial indexes should be preferred over sparse ones.

Partial indexes are very useful, and I want to use them in my project. Can I use them with mongoose?

+5
source share
3 answers

Mongoose 4.3.7 , Partial Indexes of MongoDB 3.2.

.

// ScheduleModel is a Mongoose Model
ScheduleModel.collection.createIndex({"type" : 1 } , {background:true , partialFilterExpression : { type :"g" }} , function(err , result){
     console.log(err , result);
});

, partialFilterExpression, .

+11

Mongoose +4.6.1

Book.index({user: 1, author: 1, complete: 1}, {unique: true, partialFilterExpression: {complete: true}});
+10

Mongoid:

index(
  { user_id: 1, author_id: 1, complete: 1 },
  background: true,
  partial_filter_expression:
    {
      complete: { :$eq => true }
    }
)

, .

0

Source: https://habr.com/ru/post/1626118/


All Articles