zoukankan      html  css  js  c++  java
  • mongodb的学习 (2)

    1.条件查询

    查询姓名为小明的学生                            db.local.find({name:'小明'});;

    查询英语成绩大于90分的同学                 db.local.find({score:{$gt:90}}); //查找成绩大于90分$gt

    查询数学成绩不等于88的同学                db.local.find({score:{$ne:88}});    

    查询总分大于200分的所有同学              db.local.find({score:{$gt:200}});

    $lt         小于   
    $gt        大于
    $ne       不等于
    

      截图:

     2.分页


    - `db.local.find().skip(3).limit(3);`

    - db.集合名称.find().跳到3.显示3条

    + limit 0,3

    截图:

    3.排序

    db.local.find().sort({key:排序方式});

    例如:

    升序:

    > db.local.find().sort({'score':1})
    { "_id" : ObjectId("5c1dd8b7b7c0cc1cfd4e2e59"), "contry" : "美国", "name" : "jack", "score" : 45 }
    { "_id" : ObjectId("5c1dd8b7b7c0cc1cfd4e2e5a"), "contry" : "美国", "name" : "rose", "score" : 67 }
    { "_id" : ObjectId("5c1dd8b7b7c0cc1cfd4e2e56"), "contry" : "中国", "name" : "小明", "score" : 77 }
    { "_id" : ObjectId("5c1dd8b7b7c0cc1cfd4e2e57"), "contry" : "中国", "name" : "小红", "score" : 88 }
    { "_id" : ObjectId("5c1dd8b9b7c0cc1cfd4e2e5b"), "contry" : "美国", "name" : "mick", "score" : 89 }
    { "_id" : ObjectId("5c1dd8b7b7c0cc1cfd4e2e58"), "contry" : "中国", "name" : "小张", "score" : 99 }

    降序:
    db.local.find().sort({'score':-1})
    { "_id" : ObjectId("5c1dd8b7b7c0cc1cfd4e2e58"), "contry" : "中国", "name" : "小张", "score" : 99 }
    { "_id" : ObjectId("5c1dd8b9b7c0cc1cfd4e2e5b"), "contry" : "美国", "name" : "mick", "score" : 89 }
    { "_id" : ObjectId("5c1dd8b7b7c0cc1cfd4e2e57"), "contry" : "中国", "name" : "小红", "score" : 88 }
    { "_id" : ObjectId("5c1dd8b7b7c0cc1cfd4e2e56"), "contry" : "中国", "name" : "小明", "score" : 77 }
    { "_id" : ObjectId("5c1dd8b7b7c0cc1cfd4e2e5a"), "contry" : "美国", "name" : "rose", "score" : 67 }
    { "_id" : ObjectId("5c1dd8b7b7c0cc1cfd4e2e59"), "contry" : "美国", "name" : "jack", "score" : 45 }

    截图:

    4.模糊匹配

    `db.local.find({name:{$regex:'小'}});`
    - `db.local.find({name:{$regex:'明'}});`

  • 相关阅读:
    oracle ORA01001,请求资源正忙或无效
    Flex[Embed(source='assets/error.png')]无法解析用于转换的代码错误
    正在覆盖未标记为 override 的函数
    LINUX umask详解
    C++服务器学习路线
    计算kappa系数
    umask的含义及设置
    Seurat的各种数据成员访问
    GAN训练判别器和生成器时的顺序与detach
    autograd.grad 学习
  • 原文地址:https://www.cnblogs.com/guangzhou11/p/10160964.html
Copyright © 2011-2022 走看看