mongodb translation for sql INSERT…SELECT

后端 未结 4 1225
无人及你
无人及你 2021-01-05 10:11

How to simply duplicate documents from collectionABC and copy them into collectionB if a condition like {conditionB:1} and add a timestamp like ts_imported - without knowing

4条回答
  •  猫巷女王i
    2021-01-05 10:26

    You can use javascript from mongoshell to achieve a similar result:

    db.collectionABC.find({ conditionB: 1 }).
    forEach( function(i) { 
      i.ts_imported = new Date();
      db.collectionB.insert(i);
    });
    

提交回复
热议问题