zoukankan      html  css  js  c++  java
  • [MongoDB] Remove, update, create document

    Remove:

    remove the wand with the name of "Doom Bringer" from our wandscollection.

    db.wands.remove({name: "Doom Bringer"})
    
    >> WriteResult({'ngRemoved': 1})

    When we removed the "Doom Bringer" wand, we noticed that it had a power of "Death", and we don't want any wands like that in our database. To be safe, let's remove any wands containing that in their powers.

    db.wands.remove({name: "Doom Bringer", powers: "Death"})

    Update:

    Write the command to update the wand with a name of "Devotion Shift" and set the price to 5.99.

    db.wands.update({name: "Devotion Shift"},{"$set": {price: 5.99}});

    Update all the document: "multi"

    Increase level_required by 2, apply to all the documents match {powers: "Fire"}:

    db.wands.update(
      {powers: "Fire"},
      {"$inc":{level_required: 2}},
      {"multi": true}
    )

    Create new document if there is no existing one: "upsert"

    db.logs.update(
      {name: "Dream Bender"},
      {"$inc": {count: 1}},
      {"upsert": true}
    )
  • 相关阅读:
    随笔
    打破生活的套牢
    健忘是种美德
    【转贴】怎样冒充古典高手!
    php数组中删除元素
    JS 总结
    ubuntu apache rewrite
    JS 预览超级大图
    UBUNTU 安装SVN
    Yahoo14条前端优化规则
  • 原文地址:https://www.cnblogs.com/Answer1215/p/5185369.html
Copyright © 2011-2022 走看看