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.

5

1 Answer 1

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) {})
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.