我的收藏品如下:
{
"_id" : ObjectId("520c8976586f12c80900301d"),
"IDENTITY" : "ae4ff1546ecfe6ce6e8ebb2d870d57fb",
"NAME" : "Winmain Yao",
"TYPE" : "COMPANY",
"PUBLIC" : 1,
"BACKGROUND" : null,
"CONTACT" : {
"PHONE" : {
"WORK" : "18630283895",
"HOME" : "188837283"
},
"EMAIL" : {
"DEFAULT00001" : "zxwinmain@gmail.com"
},
"IM" : [],
"SITE" : [],
"ADDRESS" : [],
"SOCIAL" : []
},
"RELATION" : {
"ACCOUNT" : "16713a29767fa4e8f139dfb249900c07",
"USER" : "84a9e7a8e5f3a13d411cfa8ff4a62a50"
},
"CREATED" : 1376553334,
"UPDATED" : 0,
"DELETED" : 0
}
现在我想给客户打电话= 18630283895,我该怎么做?
非常感谢。
答案 0 :(得分:0)
以下内容:
"PHONE" : {
"WORK" : "18630283895",
"HOME" : "188837283"
},
是错误方法。由于你总是会有更多类型的电话号码,你最终得到的“钥匙实际上是一个价值”。这使得查询(和索引)变得困难。更好的方法是:
"PHONE" : [
{ type: "WORK", number: "18630283895" },
{ type: "HOME", number: "188837283" },
],
然后您可以非常轻松地将其编入索引:
db.collection.ensureIndex( { "PHONE.number": 1 } );
使用以下内容查询数字:
db.collection.find( { "PHONE.number" : "18630283895" } );