目前,我正在管理一组包含许多成员的列表。 当涉及到字段和这些字段的命名时,每个列表看起来都不同。
通常,基本列表成员可能如此(来自我的成员集合):
{
"_id" : ObjectId("52284ae408edcb146200009f"),
"list_id" : 1,
"status" : "active",
"imported" : 1,
"fields" : {
"firstname" : "John",
"lastname" : "Doe",
"email" : "john@example.com",
"birthdate" : ISODate("1977-09-03T23:08:20.000Z"),
"favorite_color" : "Green",
"interests" : [
{
"id" : 8,
"value" : "Books"
},
{
"id" : 10,
"value" : "Travel"
},
{
"id" : 12,
"value" : "Cooking"
},
{
"id" : 15,
"value" : "Wellnes"
}
]
},
"created_at" : ISODate("2012-05-06T15:12:26.000Z"),
"updated_at" : ISODate("2012-05-06T15:12:26.000Z")
}
“fields”索引下的所有字段都是当前列表ID唯一的字段 - 这些字段可以针对每个列表ID进行更改,这意味着新列表可能如下所示:
{
"_id" : ObjectId("52284ae408edcb146200009f"),
"list_id" : 2,
"status" : "active",
"imported" : 1,
"fields" : {
"fullname" : "John Doe",
"email" : "john@example.com",
"cell" : 123456787984
},
"created_at" : ISODate("2012-05-06T15:12:26.000Z"),
"updated_at" : ISODate("2012-05-06T15:12:26.000Z")
}
目前,我的应用程序允许用户在每个海关字段中动态搜索,但由于它们没有索引,因此此过程可能非常慢。
我不相信这是允许列表创建者选择应该索引哪些字段的选项 - 但我真的需要加快速度。
有没有解决方案?
答案 0 :(得分:0)
如果您以具有字段数组的方式重构文档,则可以利用索引。
fields: [
{ name: 'fullName', value: 'John Doe' },
{ name: 'email', value: 'john@example.com' },
...
]
在fields.name和fields.value上创建索引。
当然,这不是像您的兴趣列表那样的“更深层”价值的解决方案。