Partial indexes in mongodb / mongoose

前端 未结 3 1170
暗喜
暗喜 2020-12-20 17:41

In the sparse index documentation I found note about mongodb 3.2 partial indexes

Changed in version 3.2: Starting in MongoDB 3.2, MongoDB provides the

3条回答
  •  不知归路
    2020-12-20 18:05

    In the current Mongoose version 4.3.7 you cannot define partial indexes in the scheme, but you can still use Partial Indexes of MongoDB 3.2.

    You just have to create the indexes using the native driver.

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

    After that, every query that matches the partialFilterExpression will be indexed.

提交回复
热议问题