【发布时间】:2020-04-19 17:32:06
【问题描述】:
我必须在 mongo 中存储一些模板数据并限制文档的年龄范围。下面的示例文档。
{
_id: ObjectId("unique123..."),
other data...,
filters : {
age : {
min : 18,
max : 23
}
},
{
_id: ObjectId("unique234..."),
other data...,
filters : {
age : {
min : 20,
max : 40
}
}
现在我可以使用{ $and : [{"filters.age.min": {$lt : 26}}, {"filters.age.max": {$gt : 26}}] } 查询所有模板,例如年龄 26。
有没有更高效的文档存储方式?
【问题讨论】:
-
我不确定,但看看这个:Implement Field Level Redaction in MongoDB.
-
IMO,只需将年龄存储在顶级字段中。并将过滤器模板作为您的常量(在您使用 mongodb e:g: 节点的语言/环境中),并根据这些过滤器模板准备查询。解决这个问题 - 您可能不想仅仅因为稍后这些过滤器阈值更改为其他内容而更改存储的数据。
标签: mongodb performance nosql