mongodb-将字段名称插入字符串而不是获取值
我想从已经存在的经度和纬度创建一个新的位置字段。
db.neigborhood.updateMany({}, {
$set: {
"location": {
"type": "Point",
"coordinates": ["$longitude", "$latitude"]
}
}});
我编写了应该创建新字段的代码,但是问题是我将名称作为字符串而不是字段值。
{
"_id": {
"$oid": "626a01f1df85b4b2937ece2d"
},
"latitude": "10.4980067",
"longitude": "-66.8335096",
"location": {
"type": "Point",
"coordinates": [
"$longitude",
"$latitude"
]
}
}
我做错了什么,因为我得到了“ $经度”而不是-66.8335096值?
I want to create a new location field from already existing longitude and latitude.
db.neigborhood.updateMany({}, {
$set: {
"location": {
"type": "Point",
"coordinates": ["$longitude", "$latitude"]
}
}});
I wrote this code that should create the new field, but the problem is that instead of the field values I get the names as strings.
{
"_id": {
"$oid": "626a01f1df85b4b2937ece2d"
},
"latitude": "10.4980067",
"longitude": "-66.8335096",
"location": {
"type": "Point",
"coordinates": [
"$longitude",
"$latitude"
]
}
}
What am I doing wrong that I get "$longitude" instead of the -66.8335096 value?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
与带有聚合管道的更新。
示例mongo playground
Works with Update with Aggregation Pipeline.
Sample Mongo Playground