假设我有这种文档结构,属性字段将是嵌入文档 ,并且我已经为属性.key和attributes.value编入索引如何从嵌入文档的键值类型获得确切文档结果
1-------------------------------------------------------------------------------------
{
"_id" : ObjectId("5191d8e5d00560402e000001"),
"attributes" : [
{ "key" : "pobox","value" : "QaKUWo" },
{ "key" : "city", "value" : "CBDRip" },
{ "key" : "address","value" : "zmycAa" } ],
"email" : "[email protected]",
"firstname" : "FWAUdl_2"
}
2-------------------------------------------------------------------------------------
{
"_id" : ObjectId("5191d8e7d00560402e000055"),
"attributes" : [
{ "key" : "pobox", "value" : "sNFriy" },
{ "key" : "city", "value" : "JPdVrI" },
{ "key" : "address", "value" : "phOluW" } ],
"email" : "[email protected]",
"firstname" : "hqYNWH_86"
}
我的问题是,如何查询仅基于属性字段时得到确切的文件,
db.app.find({ attributes.key:address , attributes.value:/.*uw.*/i })
查询结果并不如我所料,这应导致只有第2文件只是没了第一次文件。 我知道我在attributes.value上设置了正则表达式,我期待它只检查具有地址值的attributes.key。
如果我要过滤的另一个关键,例如像什么,
db.app.find({ attributes.key:address , attributes.value:/.*uw.*/i , attributes.key:city , attributes.value:/.*ri.*/i })
任何意见将是有益的人。 Thx。
是的,我以为我也这么做过,猜猜这不是一个高性能的选项,但它的工作原理,thx btw :) – 2013-05-15 12:21:27