In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-09 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Today, I will talk to you about how to achieve data query operation in MongoDB, many people may not know much about it. In order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.
In any database, the query operation of data is the most troublesome, while in MongoDB database, the support for query is very good.
Syntax: "db. Collection name .find ({query condition} [, {set displayed field}])"
Example: the simplest use is to use the find () function directly to complete the query
> db.info.find ()
Example: want to query the data whose url is "www.stone.com"
> db.info.find ({"url": "www.stone.com"})
{"_ id": ObjectId ("5990f8ea3268c8e84253ba3b"), "url": "www.stone.com"}
{"_ id": ObjectId ("5990f97d3268c8e84253ba3c"), "url": "www.stone.com"}
It is found that the equality relationship is also set in the form of JSON when querying data. It is impossible to do without JSON data throughout its development.
Strictly speaking, the set display field is called the data projection operation, if you do not need to display the field setting "0", but need to display the field setting "1".
Example: do not want to display "_ id"
> db.info.find ({"url": "www.stone.com"}, {"_ id": 0})
{"url": "www.stone.com"}
{"url": "www.stone.com"}
> db.info.find ({"url": "www.stone.com"}, {"_ id": 0, "url": 1})
{"url": "www.stone.com"}
{"url": "www.stone.com"}
At the same time, the query for data can also use the "pretty ()" function to format the output.
Example: formatted display
> db.info.find ({"url": "www.stone.com"}, {"_ id": 0, "url": 1}) .pretty ()
{"url": "www.stone.com"}
{"url": "www.stone.com"}
Example: query individual data
> db.info.findOne ()
{"_ id": ObjectId ("5990f8ea3268c8e84253ba3b"), "url": "www.stone.com"}
After reading the above, do you have any further understanding of how to implement data query operation in MongoDB? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.