How create a new array field with the aggregate framework

前端 未结 4 2036
礼貌的吻别
礼貌的吻别 2021-02-15 15:51

I\'m starting to use mongoDb and I\'m stuck with a simple use case.

Let\'s say I\'ve got a collection \'aCollection\' with entries such as this:



        
4条回答
  •  名媛妹妹
    2021-02-15 16:28

    You don't need the aggregation feature for this. A find, forEach, and insert is one potential approach:

    db.aCollection.find().forEach( function(myDoc) {
      myDoc.geometry = {type: "Point", coordinates: [myDoc.lat, myDoc.long]};
      db.newCollection.insert(myDoc);
    });
    

    It calls an individual insert for each document, but is quick and dirty if you have a small collection.

提交回复
热议问题