【发布时间】:2015-03-04 10:03:25
【问题描述】:
我有一个巨大的电子邮件转储,我试图在 MongoDB 中存储和查询。有 160 万封电子邮件,每封都存储为 Node module 的输出,该Node module 将原始电子邮件解析为漂亮的 Javascript 对象,如下所示:
{
"text" : "This is the text of my email",
"subject" : "Great opportunity",
"from" : [
{
"address" : "chris.wilson@example.com",
"name" : "Chris Wilson"
}
],
"to" : [
{
"address" : "person.a@example.com",
"name" : "Person A"
},
{
"address" : "person.b@example.com",
"name" : "Person B"
},
{
"address" : "person.c@example.com",
"name" : "Person C"
}
],
"date" : ISODate("2015-01-05T21:38:55.000Z")
}
我需要能够有效地查找诸如“发送到 person.a@gmail.com 的所有电子邮件”或“由 'Chris Wilson' 发送的每封电子邮件”之类的内容(无论该名称附加了哪个电子邮件地址) .
Mongo 非常愿意为我索引“to”和“from”查询,但我不确定当我这样做时查询是否有效:
db.emails.find({ "to.name": "Person A" })
这是一个覆盖查询,在作为键值对象数组的字段中查找特定属性的特定值?这个查询对我来说运行得很慢,但它又是一个大型语料库。
更新
这是将“.explain”附加到上述查询的输出:
{
"cursor" : "BasicCursor",
"isMultiKey" : false,
"n" : 24,
"nscannedObjects" : 1646837,
"nscanned" : 1646837,
"nscannedObjectsAllPlans" : 1646837,
"nscannedAllPlans" : 1646837,
"scanAndOrder" : false,
"indexOnly" : false,
"nYields" : 17088,
"nChunkSkips" : 0,
"millis" : 84685,
"server" : "DCA-TM-GUEST-iMac.local:27017",
"filterSet" : false
}
【问题讨论】:
标签: node.js mongodb indexing database