MongoDB query data

Source: Internet
Author: User
Tags findone mongodb query

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.