mongodb/猫鼬中的部分索引
Partial indexes in mongodb / mongoose
在稀疏索引文档中,我发现了关于 mongodb 3.2 部分索引
的注释
Changed in version 3.2: Starting in MongoDB 3.2, MongoDB provides the
option to create partial indexes. Partial indexes offer a superset of
the functionality of sparse indexes. If you are using MongoDB 3.2 or
later, partial indexes should be preferred over sparse indexes.
Partial indexes 非常有帮助,我想在我的项目中使用它们。是否可以将它们与猫鼬一起使用?
目前Mongoose 4.3.7版本不能在scheme中定义partial indexes,但是仍然可以使用MongoDB 3.2.
的Partial Indexes
您只需使用本机驱动程序创建索引。
// ScheduleModel is a Mongoose Model
ScheduleModel.collection.createIndex({"type" : 1 } , {background:true , partialFilterExpression : { type :"g" }} , function(err , result){
console.log(err , result);
});
之后,每个匹配 partialFilterExpression
的查询都将被编入索引。
现在可以使用 Mongoose +4.6.1 原生支持
Book.index({user: 1, author: 1, complete: 1}, {unique: true, partialFilterExpression: {complete: true}});
对于 Mongoid 用户:
index(
{ user_id: 1, author_id: 1, complete: 1 },
background: true,
partial_filter_expression:
{
complete: { :$eq => true }
}
)
找不到任何文档,但是 this PR。
在稀疏索引文档中,我发现了关于 mongodb 3.2 部分索引
的注释Changed in version 3.2: Starting in MongoDB 3.2, MongoDB provides the option to create partial indexes. Partial indexes offer a superset of the functionality of sparse indexes. If you are using MongoDB 3.2 or later, partial indexes should be preferred over sparse indexes.
Partial indexes 非常有帮助,我想在我的项目中使用它们。是否可以将它们与猫鼬一起使用?
目前Mongoose 4.3.7版本不能在scheme中定义partial indexes,但是仍然可以使用MongoDB 3.2.
的Partial Indexes您只需使用本机驱动程序创建索引。
// ScheduleModel is a Mongoose Model
ScheduleModel.collection.createIndex({"type" : 1 } , {background:true , partialFilterExpression : { type :"g" }} , function(err , result){
console.log(err , result);
});
之后,每个匹配 partialFilterExpression
的查询都将被编入索引。
现在可以使用 Mongoose +4.6.1 原生支持
Book.index({user: 1, author: 1, complete: 1}, {unique: true, partialFilterExpression: {complete: true}});
对于 Mongoid 用户:
index(
{ user_id: 1, author_id: 1, complete: 1 },
background: true,
partial_filter_expression:
{
complete: { :$eq => true }
}
)
找不到任何文档,但是 this PR。