连接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();