Shankar Mane
07/28/2023, 6:25 PM-- INSERT Only collection (This is possible using "UpdateOneModel" and it's working as expected.)
db.cid.findOneAndUpdate(
{ _id: { "userid": 1, "cid": 101} },
[
{ $set: { updatedAt: new Date()} },
{ $set: { finishtype: { $concatArrays: [ [1001], { $ifNull: [{ $getField: "finishtype" }, []] }] }}},
],
{ upsert: true}
);
-- STUCK HERE
-- UPDATE from above collection (cid) to NEW collection (score)
db.cid.find({ _id: { "userid": 1, "cid": 101} }).forEach(
function (elem) {
db.scores.updateOne(
{
_id: elem._id.userid
},
[
{ $set: { finishtype: { $slice: [ { $concatArrays: [ [ { $concatArrays: [[1002], { "$ifNull": [elem.finishtype, []] } ] } ], { "$ifNull": [ { $getField: "finishtype" }, []] } ] }, 5 ] } } }
],
{ upsert: false}
);
});