【发布时间】:2016-05-10 16:03:57
【问题描述】:
我是 MongoDB 的新手,一直在研究模式设计和索引。我知道您可以索引一个属性,而不管它的值(ID、数组、子文档等)如何,但我不知道索引字符串数组或嵌套对象的键是否有性能优势。
这是我正在考虑的两种情况的示例(在 Mongoose 中):
// schema
mongoose.Schema({
visibility: {
usa: Boolean,
europe: Boolean,
other: Boolean
}
});
// query
Model.find({"visibility.usa": true});
或
// schema
mongoose.Schema({
visibility: [String] // strings could be "usa", "europe", and/or "other"
});
// query
Model.find({visibility: "usa"});
文档可以有一个、两个或所有三个可见性选项。
此外,如果我采用布尔对象设计,我可以简单地索引可见性字段还是需要在美国、欧洲和其他国家/地区建立索引?
【问题讨论】:
标签: performance mongodb indexing mongoose schema