I have this script:
let offersToUpdate = [];
let offersToRemove = [];
while (await cursor.hasNext()) {
let offer = await cursor.next();
let product = await db.collection('products').findOne({_id: offer.product._id});
if (product == null) {
offersToRemove.push(offer._id);
} else {
offersToUpdate.push(offer._id);
}
}
await db.collection('offers').update({_id: {$in: offersToUpdate}});
await db.collection('offers').remove({_id: {$in: offersToRemove}});
When I execute it I have this error:
document must be a valid JavaScript object
Do you have any idea why I have it?
Thanks!
The update method requires two parameters, one filter parameter and another update parameter. As per the code you have only provided one parameter, pls refer to official documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With