zoukankan      html  css  js  c++  java
  • mongodb数据查询

    连接mongodb;

    右键单击数据库,选择Open IntelliShell;

    输入查询语句,执行;

    1、简单的等于。

        查询geoData集合中,poleInfoID=4的数据。db.geoData.find({poleInfoID:4})  

    2、<, <=, >, >= ($lt, $lte, $gt, $gte )

        查询poleInfoID=4且20200320134032032<=synchroID<=20200320134032300的数据。

           db.geoData.find({poleInfoID:4,synchroID: {$gte:20200320134032032},synchroID: {$lte:20200320134032300}})    

           db.geoData.find({poleInfoID:4,synchroID: {$gte:20200320134032032,$lte:20200320134032300}})

    3、使用or

         select name, age, skills from users where name = 'hurry' or age = 18;

        db.users.find({ '$or' : [{'name' : 'hurry'}, {'age' : 18}] },{'name' : 1, 'age' : 1, 'skills' : 1});

    4、使用in, not in ($in, $nin)

        select * from users where age in (10, 22, 26);

        db.users.find({'age' : {'$in' : [10, 22, 26]}});

    5、 匹配null

        select * from users where age is null;

        db.users.find({'age' : null);

    6、like (mongoDB 支持正则表达式)

        select * from users where name like "%hurry%";

        db.users.find({name:/hurry/}); 

        select * from users where name like "hurry%";

        db.users.find({name:/^hurry/}); 

    7、使用distinct

        select distinct (name) from users;

        db.users.distinct('name');

    8、使用count

        select count(*) from users;

        db.users.count();

  • 相关阅读:
    git相关整理
    cookie、sessionStorage和localStorage
    AJAX学习笔记
    json web token
    加密算法
    单点登陆
    给手机网络添加手动代理
    oracle数据库索引
    类加载器
    类加载过程
  • 原文地址:https://www.cnblogs.com/vivih-y/p/12698951.html
Copyright © 2011-2022 走看看