Reverse array field in MongoDB

后端 未结 2 1065
一整个雨季
一整个雨季 2021-01-19 10:44

I have a collection with a location field that was entered in the wrong order:

location: [38.7633698, -121.2697997]

When I try to place a 2

2条回答
  •  被撕碎了的回忆
    2021-01-19 11:23

    db.loc.find().forEach(function (doc) {
        var loc = [ doc.location[1], doc.location[0] ]; 
        db.loc.update(doc, { $set: { location: loc } });
    })
    

提交回复
热议问题