2

I need to insert a list of elements and check if the element exists in database, if the element exists then the element will be update.

I used upsert and array:

    dbo.collection("Ebooks").update(arrayValues, {upsert: true, multi: true},function(err, res) {
         if (err) throw err;
         console.log("finish");
         db.close();
    });  

Array eg:

[{_id: 10, name='Teste1'}, {_id: 11, name='Teste2'}]

And is returning this error:

MongoError: BSON field 'update.updates.q' is the wrong type 'array', expected type 'object'

How I convert Array to this Object?

Thanks.

user3434888
  • 41
  • 1
  • 6

1 Answers1

1

Not sure, but looks like you don't pass query(first parameter), what data should de updated.

dbo.collection("Ebooks").update((), arrayValues, {upsert: true, multi: true},function(err, res) {})

or

dbo.collection("Ebooks").update((_id:someValue), arrayValues, {upsert: true, multi: true},function(err, res) {})
Helen
  • 176
  • 10