简体   繁体   中英

MongoDB : “unexpected token” error when trying to Update document field that is an array

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?

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM