如何在mongodb中处理geolocation(point)对象中的空值?
我目前正在与一个mongodb合作,该mongodb包含一系列具有以下结构的公司:如何在mongodb中处理geolocation(point)对象中的空值?,mongodb,null,geospatial,point,Mongodb,Null,Geospatial,Point,我目前正在与一个mongodb合作,该mongodb包含一系列具有以下结构的公司: { "_id": "52cdef7c4bab8bd675297d8e", "name": "Facebook", "offices": [{ "description": "Headquarters", "address1": "1601 Willow Road", "address2": "", "zip_code": "9
{
"_id": "52cdef7c4bab8bd675297d8e",
"name": "Facebook",
"offices": [{
"description": "Headquarters",
"address1": "1601 Willow Road",
"address2": "",
"zip_code": "94025",
"city": "Menlo Park",
"state_code": "CA",
"country_code": "USA",
"latitude": 37.41605,
"longitude": -122.151801,
"location": {
"type": "Point",
"coordinates": [-122.151801, 37.41605]
}
}, {
"description": "Europe HQ",
"address1": "",
"address2": "",
"zip_code": "",
"city": "Dublin",
"state_code": null,
"country_code": "IRL",
"latitude": 53.344104,
"longitude": -6.267494,
"location": {
"type": "Point",
"coordinates": [-6.267494, 53.344104]
}
}, {
"description": "New York",
"address1": "340 Madison Ave",
"address2": "",
"zip_code": "10017",
"city": "New York",
"state_code": "NY",
"country_code": "USA",
"latitude": null,
"longitude": null,
"location": {
"type": "Point",
"coordinates": [null, null]
}
}]
}
我想在“位置”字段上创建地理空间索引:
db.startups.createIndex( { "offices.location" : "2dsphere" } )
但是,有些办公室的经度和纬度为空值,因此索引创建失败,因为点必须仅包含数字元素
我的问题是我应该和/或可以如何处理这个问题。只需删除违规元素的整个位置:
"location": {
"type": "Point",
"coordinates": [null, null]
}