0
我有一个包含这样的数据seeds.js文件:为什么Mongoose(MongoDB)在保存后重新排列我的数组?
var newBus = new Bus({
am: {
route: [
{
coords: {lat: 35.645329, lng: -84.068154},
address: "5408 Hutton Ridge Rd"
}
}
}
,当我打电话
newBus.save(function(err, data) {
if (err) throw err;
else console.log(data);
});
它存储的是这样的:
"am" : {
"route" : [
{
"address" : "5408 Hutton Ridge Rd",
"coords" : {
"lng" : -84.068154,
"lat" : 35.645329
}
}
]
}
我只是注意到它将lat, lng
的顺序改为lng, lat
。我不认为这是重要的,但是当我对种子数据进行更新时,更新仅在找到匹配特定lng, lat
的数组时才起作用。当我试图找到与lat, lng
匹配时,它不起作用。
那么为什么MongoDB/Mongoose重新排列数据?
好的,这是有道理的。但显然,MongoDB不会随机存储它,而lng,lat不是按字母顺序排列的,为什么它最终会以这种方式排序呢? –
我想更大的问题是,我应该依赖它作为lng,lat如果它不总是以这种方式排序? –
我不是MongoDB主题的专家,但你可以检查这个问题:http://stackoverflow.com/questions/18514188/how-can-you-specify-the-order-of-properties-in-a-javascript -object-for-a-mongodb看起来作者很担心和你一样的东西 – Morishiri