-
MongoDB install pit:
-
Mongo use:
-
PS: A collection in MongoDB is a table, and a document is a piece of data
-
Select and create a database syntax format: use database name
-
Syntax format for inserting documents: db. collection name.
-
Find (); db.set noun.find ();
-
FindOne ({userID :’1013′}); findOne({userID :’1013′});
-
Find ([optional condition]). Limit (Number of returned data items);
-
Modify the syntax format of the document: db. collection name. update(condition, modified data)
- Db.spit. update({_id:”1″},{visits:NumberInt(1000)});
- Db.spi. update({_id:”2″},{$set:{visits:NumberInt(2000)}});
-
Delete document: db. collection name. Remove (condition);
-
Db. Collection name. Remove ({});
-
Count (); db. set name. count();
-
Count ({[optional condition]}); count({[optional condition]}); count({[optional condition]});
-
Fuzzy query: / Fuzzy query string /
- Db.spi. find({content:/ traffic /})
- Db.spi. find({content:/^ work overtime /})
-
Greater than, less than, not equal to:
- Find ({“field” : {$gt: value}}) // greater than: field > value
- Find ({“field” : {$lt: value}}) // Less than: field < value
- Find ({“field” : {$gte: value}}) // Greater than or equal to: field >= value
- Find ({“field” : {$lte: value}}) // Less than or equal to: field <= value
- Find ({“field” : {$ne: value}}) = value
-
Include, not include:
- Db.spi. find({userid:{$in:[“1013″,”1014”]}})
- Db.spi. find({userid:{$nin:[“1013″,”1014”]}})
-
Conditional connection:
- If we want a query that meets more than two criteria, we need to use the $and operator to associate the criteria. (and) phase when the SQL format for: $and: [{}, {}, {}], example: db. The spit. Find ({$and: [{visits: {$gte: 1000}}, {visits: {$lt: 2000}}]})
- $or:[{},{},{}] $or:[{},{},{}] db.spit.find({$or:[ {userid:”1013″} ,{visits:{$lt:2000} }]})
-
Column value growth:
- Db.spi. update({_id:”2″},{$inc:{visits:NumberInt(1)}})
-
-
Use MongoDB in Java code:
- Import maven dependencies:
- Query:
- Insert: