• MongoDB数据库的CURD操作命令


    1、增加:
    MongoDB 使用 insert() 或 save() 方法向集合中插入文档
    语法如下:db.COLLECTION_NAME.insert(document)


    2、删除:remove() 方法
    基本语法:
    db.collection.remove(
    <query>,
    <justOne>
    )

    如果你的 MongoDB 是 2.6 版本以后 ,语法为:
    db.collection.remove(
    <query>,
    {
    justOne: <boolean>,
    writeConcern: <document>
    }
    )

    参数说明:
    query :(可选)删除的文档的条件。
    justOne : (可选)如果设为 true 或 1,则只删除一个文档。
    writeConcern :(可选)抛出异常的级别。


    3、修改:update() 方法
    语法:
    db.collection.update(
    <query>,
    <update>,
    {
    upsert: <boolean>,
    multi: <boolean>,
    writeConcern: <document>
    }
    )

    参数说明:
    1、query : update的查询条件,类似sql update查询内where后面的。

    2、update : update的对象和一些更新的操作符(如,,inc…)等,也可以理解为sql update查询内set后面的

    3、upsert : 可选,这个参数的意思是,如果不存在update的记录,是否插入objNew,true为插入,默认是false,不插入。

    4、multi : 可选,mongodb 默认是false,只更新找到的第一条记录,如果这个参数为true,就把按条件查出来多条记录全部更新。

    5、writeConcern :可选,抛出异常的级别。

    4、查询
    find() 方法以非结构化的方式来显示所有文档。
    pretty() 方法以格式化的方式来显示所有文档。
    findOne() 方法,它只返回一个文档。

    语法:
    db.collection.find(query, projection)

    参数说明:
    query :可选,使用查询操作符指定查询条件
    projection :可选,使用投影操作符指定返回的键。查询时返回文档中所有键值, 只需省略该参数即可(默认省略)。
    如果你需要以易读的方式来读取数据,可以使用 pretty() 方法

  • 相关阅读:
    Proximal Algorithms 5 Parallel and Distributed Algorithms
    Proximal Algorithms 4 Algorithms
    Proximal Algorithms 3 Interpretation
    Proximal Algorithms 2 Properties
    Proximal Algorithms 1 介绍
    matplotlib 高阶之Transformations Tutorial
    matplotlib 高阶之patheffect (阴影,强调)
    matplotlib 高阶之path tutorial
    Django Admin Cookbook-19如何在管理后台中一个模型只允许创建一个对象
    Django Admin Cookbook-18如何限制对Django Admin管理部分功能的使用
  • 原文地址:https://www.cnblogs.com/x0815/p/12334596.html
Copyright © 2020-2023  润新知