Basic query statements of MogoDB and basic usage in Robo 3T

In addition to the Mysql database, I also often need to use the MogoDB database. Just like the mysql table, it is faster to query with the Navicat visualization tool. The tool used by MogoDB is robo 3T, and the query statement is different from the sql statement.

1. Check all

db.getCollection('CollectionName').find()

2. Query according to conditions

db.getCollection('CollectionName').find({"userId":37761});

3. Multi-condition query

db.getCollection('CollectionName').find({"userId":1},{"customerId":61});

4. Query according to the timestamp range

db.getCollection('CollectionName').find({"userId":61},{"timestamp":{" $gt ":1540449300000,"$lte":1540550100000}})

5. Condition check sorting and paging: 1. is ascending order, -1 is descending order

db.getCollection('CollectionName').find({"userId":361}).sort({"time":-1}).limit(10);

Basic sentence pattern

search result

6. Use $and to query multiple conditions

db.getCollection('CollectionName').find( {$and:[{"userId":37761},{"domain":"time.com"},{"timestamp":{"$gt":1540483200000,"$lte":1540550100000}}]});

The corresponding range identifier in mongodb:

"$lt"===================>  "<"       
"$lte"==================>  "<="      小于Less than
"$gt"===================>  ">"       大于[数] greater than
"$gte"==================>  ">="
"$ne"===================>  "!="
"$nin"===================> 不存在于....内

7. ISOdate time range query

 db.getCollection('CollectionName').find({ "timestamp" : { "$gte" : ISODate("2018-04-20T00:00:00Z"), "$lt" : ISODate("2018-04-21T00:00:00Z") }});

8. Insert

db.CollectionName.insert({"url":"www.baidu.com"});

Guess you like

Origin blog.csdn.net/Yorkie_Lin/article/details/95380848