【发布时间】:2016-04-23 18:58:41
【问题描述】:
如果我使用 mongoose 用这样的简单查询查询 MongoDB:
User
.find()
.where('address.loc').near({ center: [lat,lng], maxDistance: 1 })
.exec(function(err, result) {
if (err) {
request.log(['server', 'database', 'error'], 'An error occured during the execution of the query');
}else{
for(var i=0;i<result.length;++i){
result[i]["distance"] = 5;
}
console.log(result[0].distance);
console.log(result[0])
}
});
第一个 console.log 打印:5
但第二个打印:
{ address: { loc: [ 37.0814402, 15.287517 ], value: 'viale tica' },
tags: [ 'Primi', 'Secondi' ],
__v: 0,
cap: 96100,
ad_number: 15,
business_email: 'prova@provbhifbvvyvg',
_id: 571b3b78249a2e160b4eee3f }
为什么这个文档和结果数组中的其他文档没有字段距离?
【问题讨论】:
标签: json node.js mongodb mongoose