zoukankan      html  css  js  c++  java
  • mongo find

    MongoVUE

    对应成语句,结构如下:

    db.logs.find({ "message" : /消息/ }, { "message" : 1 }).limit(50).sort({ "timestamp" : -1 });

    现有学生表(姓名,年龄,时间)

    create table student
    (
    NAME VARCHAR2(100),
    AGE NUMBER(2),
    CREATETIME TIMESTAMP(6)
    )

    1. 检索全部

    select * from student

    db.student.find({ });

    2. 检索某些字段(0:不存在,1:存在),存在模式下只显示指定的字段,不存在模式下不显示指定的字段

    select name from student

    db.student.find({ }, { "name" : 0 })

    3.排序(-1:desc, 1:asc)

    select * from student order by age desc 

    db.student.find({ }).sort({ "age" : -1 });

    4.值等

    select * from student where name='小明'

    db.student.find({ "name" : "小明" });

    5.like

    select * from student where name like '%旭%'

    db.student.find({ "name" : /旭/ });

    6.and

    select * from student where name like '%旭%' and age =22

    db.student.find({ "name":/旭/,"age":22});

    7.or

    select * from student where name like '%旭%' or age=22

    db.student.find({ "$or" : [{ "name" : /旭/ }, { "age" : 22 }] });

    8.<, <=, >, >= ($lt, $lte, $gt, $gte )

    select * from student where age >=18 and age <=20

    db.student.find({ "age" : { "$gte" : 18,"$lte" : 20 } });

    9. 日期比较大小(Mongodb 中 Type 为 DateTime)

    select * from student where createtime >= to_date('2015-06-01 10:10:10','YYYY-MM-DD HH24:MI:SS')

    db.student.find({"createtime":{"$gte":ISODate("2015-06-01T10:10:10Z")}});

    10.limit

    select * from student limit 1

    db.student.find({}).limit(1)

    11. 不区分大小写检索

    mysql 默认不区分大小写,可通过 binary(your_field_which_you_want_match_case) = 'your_value'

    db.student.find({"your_field_case_sensitive":{"$regex":"your_keyword_no_need_to_match_case","$options":"i"}})

    ps:中国+8 时区,mongodb 0 时区 (db)

         查询时要以0时区为准(+8时间-8小时)

  • 相关阅读:
    ubuntu18.04登录界面背景图的更换
    java面向对象基础知识
    java语法+变量
    sql查询
    sql的增删改查
    事件概念和事件监听
    DOM对HTML元素的增删改操作
    DOM对HTML元素访问操作2
    DOM对HTML元素访问操作
    BOM模型中常用对象的介绍
  • 原文地址:https://www.cnblogs.com/zno2/p/4544255.html
Copyright © 2011-2022 走看看