Mongodb

作者: writ | 来源:发表于2019-07-06 21:11 被阅读0次

    1.数据库操作:
    use database; db.dropDatabase(); show dbs;
    mongodump 备份 mongorestore恢复 mongostat监控mongotop
    2.集合操作
    db.createCollection() db.collection.insert()
    db.collection.drop() db.collection.renameCollection()
    show collections db.getCollection('class')
    3.文档插入
    insertOne() insertMany() insert() save()
    4.查找函数
    find(query,field)
    5.数据操作
    db.collection.findOne(query,field)

    1. query操作符的使用
      (1) eq == = (括号成对写,格式最重要) example: db.class0.find({age:{eq:17}},{_id:0})
      (2) lt == < example: db.class0.find({name:{lt:'Tom'}},{_id:0})
      (3) gt == > example: db.class0.find({age:{gt:17,lt:20}},{_id:0}) (4)lte gtene innin
      7.逻辑操作符 (与:遇假则假,或:遇真则真,非:真变假,假变真)
      (1) and example: db.class0.find({and[{gt:17},{age:{in:[17,18,21]}}],{_d:0}}) (2)or notnor
      8.数组操作符
      (1) 查找数组中包含的元素
      (2)all 查找数组中包含多项 (3)size 根据数组中元素的个数
      #(4)$slice 用于feild参数,表示查找数组中的哪些项
      (5)db.class0.distinct('age') db.class0.find().pretty()
      db.class0.find().limit(n){前n条数据}
      db.class0.find().skip(n){跳过前n条数据}
      db.class0.find().count(){统计数据数目}
      db.class0.find().sort({field:1/-1}){数据排序}
      ## 函数可以连续调用
      ## 可以利用序列号获取

    相关文章

      网友评论

          本文标题:Mongodb

          本文链接:https://www.haomeiwen.com/subject/enhmhctx.html