如何用mongodb反转坐标?

fjnneemd  于 2022-12-12  发布在  Go
关注(0)|答案(1)|浏览(109)

这些坐标的顺序不对,我需要为所有集合反转它们:

{
  _id: ObjectId("638f9866d9014fabfc47275e"),
  address: '801 Pine St, Anchorage, AK',
  name: 'Russian Jack Skatepark',
  location: { type: 'Point', coordinates: [ 61.214855, -149.793563 ] }
}
g2ieeal7

g2ieeal71#

You can use $reverseArray as follow:

db.collection.updateMany({},
[
{
$set: {
  "location.coordinates": {
    $reverseArray: "$location.coordinates"
   }
  }
 }
])

Playgrouund

相关问题