search

Home  >  Q&A  >  body text

mongoDB的update查询条件?

小白提问.

db.users.insert({"name": "demo"})

以上插入十遍.

db.users.update({"name": "demo"}, {$set: {"age": 24}})

这条案例来说应该十条记录全部匹配上,但是为什么仅仅匹配了第一条呢?

我想大声告诉你我想大声告诉你2802 days ago767

reply all(3)I'll reply

  • 世界只因有你

    世界只因有你2017-04-28 09:08:34

    https://docs.mongodb.org/getting-started/shell/update/#update-multiple-documents

    reply
    0
  • ringa_lee

    ringa_lee2017-04-28 09:08:34

    The foundation is not very solid, please read the manual more.

    db.users.update({"name": "demo"}, {$set: {"age": 24}},{multi: true})
    
    db.collection.update(
       <query>,
       <update>,
       {
         upsert: <boolean>,
         multi: <boolean>,
         writeConcern: <document>
       }
    )
    

    reply
    0
  • 阿神

    阿神2017-04-28 09:08:34

    db.users.update({},{},true,true) The contents in the curly brackets remain unchanged. The default is to update one item. Just add the two parameters true!

    reply
    0
  • Cancelreply