I am running from mongosh. Can I use the “db” and “col” variable in the into: { db:“db”, coll:“col”} of the merge? Or does a better approach exist?
thanks in advance.
var db = db.getSiblingDB('db_test');
var col = db.product;
function convert() {
col.aggregate(
[ { $match :{"Quantity": { $type: 1 }}},
{ $addFields:{"Quantity": { $convert:
{input: "$Quantity", to: "int" }}}},
{ $merge :{ into: { db:"db", coll:"col"}, on: "PartId", whenMatched: "replace"} }
], {allowDiskUse: true} )
};