【发布时间】:2018-12-19 16:44:51
【问题描述】:
MongoDB 对象结构
{
"_id" : ObjectId("59db626f6944c019616eb9cf"),
"category" : "Flat",
"purpose" : "SALE",
"price" : 2000,
"area" : 2,
"lotArea" : 2,
"description" : "nothing",
"features" : {
"beds" : 3,
"baths" : 3,
"totalRooms" : 2,
"dining" : true,
"furnishing" : true,
"flooring" : true,
"servantQuarter" : true,
"waterHeating" : true,
"ceiling" : true,
"cooling" : "Central",
"heating" : "Central",
"installedAppliances" : [
"nothing"
]
},
"dealerId" : [ ],
"images" : [ ],
"loc" : {
"latitude" : "33.652324769150894",
"longitude" : "72.95517927486878"
},
"address" : {
"city" : "Islamabad",
"house_no" : "1",
"street_no" : "1",
"sector" : "G-13",
"area_description" : "commercial"
},
"__v" : 0
}
{
"_id" : ObjectId("59db62a06944c019616eb9d0"),
"category" : "Flat",
"purpose" : "SALE",
"price" : 2001,
"area" : 1,
"lotArea" : 1,
"description" : "nothing",
"features" : {
"beds" : 2,
"baths" : 2,
"totalRooms" : 2,
"flooring" : true,
"furnishing" : true,
"ceiling" : true,
"waterHeating" : true,
"servantQuarter" : true,
"dining" : true,
"cooling" : "AC",
"heating" : "Central",
"installedAppliances" : [
"nothing"
]
},
"dealerId" : [ ],
"images" : [ ],
"loc" : {
"latitude" : "33.65243977011859",
"longitude" : "72.9547689790985"
},
"address" : {
"city" : "Islamabad",
"house_no" : "11",
"street_no" : "1",
"sector" : "G-13",
"area_description" : "dd"
},
"__v" : 0
}
{
"_id" : ObjectId("59db7ae1bfbdd82adf9c5ddc"),
"category" : "Flat",
"purpose" : "SALE",
"price" : 20000,
"area" : 2,
"lotArea" : 2,
"description" : "nothing",
"features" : {
"beds" : 2,
"baths" : 2,
"totalRooms" : 1,
"ceiling" : true,
"furnishing" : true,
"flooring" : true,
"waterHeating" : true,
"dining" : true,
"servantQuarter" : true,
"cooling" : "AC",
"heating" : "Heaters",
"installedAppliances" : [
"nothing"
]
},
"dealerId" : [ ],
"images" : [ ],
"loc" : {
"latitude" : "33.664966530995855",
"longitude" : "72.99625174581297"
},
"address" : {
"city" : "Islamabad",
"house_no" : "1",
"street_no" : "1",
"sector" : "G-11",
"area_description" : "commercial"
},
"__v" : 0
我想查询一些基于空和非空字符串的数据,例如
db.properties.find({"purpose":"SALE,"address.city":""}).pretty()
如果用户输入“目的”值但未输入“address.city”值,则只有那些用于销售目的的数据应返回,并且如果用户输入了“address.city”值例如
db.properties.find({"purpose":"SALE,"address.city":"Islamabad"}).pretty()
现在数据必须是针对特定城市的销售。
实际上,我需要用于高级搜索的那种查询类型,它处理 $and 逻辑条件中的值(如果为空或不为空),并且我有一长串可能应该在用户高级搜索选择中从 MongoDB 查询数据的可能性。
【问题讨论】:
标签: mongodb mongodb-query