Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Document must be a valid JavaScript object

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!

like image 459
Anna Avatar asked Jul 08 '26 05:07

Anna


1 Answers

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.

like image 90
Player78 Avatar answered Jul 09 '26 19:07

Player78



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!