1
我有一個表示移動物體貓鼬方案更新GeoJSON的
var vehicleSchema = new Schema({
properties:{
obj:String,
name:String,
id:String
},
geometry : {
type: {type : String},
coordinates : [ Number, Number ]
}
});
,我試圖用下面的對象和命令,如果我進入這工作完美的蒙戈控制檯,但不更新來更新它下面的貓鼬架構該文檔在節點函數中使用時。
這是對象要更新:
var updatedVehicle = new Vehicle(
{properties:{
obj:"Answer",
name:"is",
id:"42"
},
geometry:{
type:"Point",
coordinates:[42,42]
}
})
這是update命令
Vehicle.update(
{$and:[
{'properties.obj':data.properties.obj},
{'properties.id':data.properties.id}
]},
{$set:
{properties:data.properties, geometry:data.geometry}
},
{upsert: true},
cb
)
我知道,貓鼬有一些quirks when it comes to GeoJSON,我希望這只是一個又一個。
,但不說偏離GeoJSON格式?基於該格式,類型字段用於存儲類型。 – Dimitris 2014-10-09 12:23:50
@Dimitris我沒有看過GeoJSON規範,但是mongo不需要設置類型屬性,實際上模式只是一個貓鼬抽象,它不會在貓鼬上反映出來,除了像'index'這樣的特定情況。但是,它確實需要在運行geospacial查詢時指定類型,如下所示http://docs.mongodb.org/manual/tutorial/query-a-2dsphere-index/ – Jakeii 2014-10-09 13:16:40
所以,我的理解是,我不需要只要我有幾何標記索引,並在進行地理空間查詢時使用該類型,就擔心模式。 這意味着我可以用{geometry,[x,y],index:'2dsphere'}創建一個新對象順便說一下,我更喜歡使用「testV.index({'geometry':'2dsphere'}) ;」一次在模式中,而不是將其添加到每個新對象。 我會做一些測試並回來。 ; - – Dimitris 2014-10-09 15:11:12