Query data using DB. Table name. Find () query data If you do not specify a condition, the default query is all for example > Db.noPK.find () {"_id": ObjectId ("5a50642b908e6b07a84472a2"), " Name ":" JavaScript "," Value ":" Vue.js "} {" _id ": ObjectId (" 5a50703c908e6b07a84472a6 ")," name ":" Shell "," type ":" Scri PT "} Specify condition Query > Db.noPK.find ({" Name ":" Shell "}) {" _id ": ObjectId (" 5a50703c908e6b07a84472a6 ")," name ":" Shell "," Type ":" Script "} if you want the displayed data to be formatted, use pretty () such as:> Db.noPK.find ({" Name ":" Shell "}). Pretty () {" _id ": ObjectId (" 5a50703c908e6b07a84472a6 ")," name ":" Shell "," type ":" Script "} query condition $lt Less than for example {" age ": {$lt: +}} $lte less than or equal to {" age ": { $lte: +}} $gt greater than for example {"age": {$gt: +}} $gte greater than or equal to $ne not equal to $or logic or for example Db.user.find ({"$or": [{"Hobby": "Swimming"},{"gender": " Female "}]},{" _id ": 0}" {"Hobby": "Swimming", "gender": "Female"} {"hobby": "Swimming", "gender": "Male"} query table in total How many data use the. Count () method such as db.nopk.find (). Count () query only one data using FindOne () If you do not give a parameter, the first data is returned by default, if you specify a condition for the query, Returns the first article that is queried based on a condition For example, get a piece of data, do not specify a condition: Db.noPK.findOne () Specify condition Db.noPK.findOne ({"Name": "JavaScript"}) if you want to query and delete a piece of data you can use Findoneanddelete () The same if you don't specify a condition Delete the first data in the table by default For example: Db.noPK.findOneAndDelete () Specify condition Db.noPK.findOneAndDelete ({"Name": "was"})
MongoDB Query Data