mongodb:如何为mongo的地理定位功能添加新属性

时间:2015-03-23 02:25:01

标签: mongodb mongoose

我在mongodb中有一系列事件,下面是该集合中文档的示例:

{

"id" : 15178390976,   
    "title" : "Basics of Writing a Business Plan (Essex Office)",   
    "end_date" : "2015-03-18 11:00:00",   
    "venue" :   
    {   
        "city" : "Essex",   
        "name" : "WindsorEssex Small Business Centre (Essex Office)",   
        "country" : "Canada",   
        "region" : "Ontario",   
        "longitude" : -82.823545,   
        "postal_code" : "N8M 2J3",    
        "address" : "39 Maidstone Avenue East",   
        "latitude" : 42.17792,   
        "id" : 8864285,   
        "Lat-Long" : "42.17792 / -82.823545"  
      }  
}

我想修改文档集合,以便我可以在MongoDB中应用地理空间球形函数。我想修改集合中的所有文档,如下所示:

{   
    "id" : 15178390976,   
    "title" : "Basics of Writing a Business Plan (Essex Office)",   
    "end_date" : "2015-03-18 11:00:00",   
    "venue" :   
    {   
        "city" : "Essex",   
        "name" : "WindsorEssex Small Business Centre (Essex Office)",   
        "country" : "Canada",   
        "region" : "Ontario",   
        "longitude" : -82.823545,   
        "postal_code" : "N8M 2J3",     
        "address" : "39 Maidstone Avenue East",   
        "latitude" : 42.17792,    
        "id" : 8864285,   
        "Lat-Long" : "42.17792 / -82.823545"  
    },  
    location:  
    {  
        "type":"Point",  
        "coordinates":[-82.823545, 42.17792]  
    }  
}  

坐标中的值来自venue.longitudevenue.latitude

如何将文档更新为我想要的内容?我在聚合中尝试了$update$projection,但它们都不适用于location.coordinates属性。我没能将值推送到数组中。

我使用的聚合是:

db.coll.aggregation([ 
    { $project:
        {
            "id": "$id",  
            "title":"$title",
            "venue":"$venue",
            "location.type": "Point",
            "location.coordinate":["$venue.longitude","$venue.latitude"]
        }  
    },
    { $out:newoutput }
])

任何人都可以帮助我吗?

0 个答案:

没有答案