0

I have a collection called Names with a document that looks like this:

{
   "_id":33,
   "listOfNames" : ["John", "Fred", "Andy"]
}

I am trying to do an update command that looks like the following:

db.Names.update{{}, {$set: {"listOfNames" : ["John", "Mary"]}, {multi:true})}

This fails with "unexpected token". What is the correct syntax to use when updating a field in a series of documents when the field is an array?

1 Answer 1

3

use this query

db.Names.update({}, 
{
    $set: {"listOfNames":["John", "Mary"]},     
}, { multi : true })
  • Anyway you put redundant { after update function, You should use (
  • And you put ) in wrong place
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.