In addition to Weibo, there is also WeChat
Please pay attention

WeChat public account
Shulou
 
            
                     
                
2025-11-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)06/01 Report--
MongoDB queries documents using the find () method.
The find () method displays all documents in an unstructured way.
The syntax format is as follows:
Db.collection.find (query, projection)
Query: optional, use the query operator to specify query conditions
Projection: optionally, use the projection operator to specify the returned key. When querying, all the key values in the document are returned, simply omitting the parameter (default omitted).
# after adding the pretty method to find, you can also display it in a format that is easier to read:
Db.tmp.find ()
{"_ id": ObjectId ("5c1757c7f4e84940e0bd578b"), "name": "aaa", "pwd": "123"," birthday ": ISODate (" 1995-09-05T00:00:00Z ")}
{"_ id": ObjectId ("5c1757f5f4e84940e0bd578c"), "name": "bbb", "pwd": "321", "birthday": ISODate ("1999-10-10T00:00:00Z")}
{"_ id": ObjectId ("5c177b84f4e84940e0bd578d"), "name": "suhaozhi", "pwd": "suhaozhi", "phone": [{"phone_num": "13333333333", "type": "cmcc"}, {"phone_num": 1555555555, "type": "chinanet"}], "type": "chinanet"}
{"_ id": ObjectId ("5c177ba1f4e84940e0bd578e"), "name": "suhaozhi", "pwd": "su", "phone": [{"phone_num": "13333333332", "type": "cmcc"}, {"phone_num": 15655555555, "type": "cnnet"}]}
{"_ id": ObjectId ("5c178a62b1d327866c98c9f7"), "x": "y"}
{"_ id": ObjectId ("5c1f226c87756129d06d2718"), "username": "aaa", "phone_num": "13333333333"}
{"_ id": ObjectId ("5c1f232587756129d06d2719"), "username": "bbb", "phone_num": ["123,456"]}
Mgset-6039947:PRIMARY > db.tmp.find (). Pretty ()
{
"_ id": ObjectId ("5c1757c7f4e84940e0bd578b")
"name": "aaa"
Pwd: 123,
Birthday: ISODate ("1995-09-05T00:00:00Z")
}
{
"_ id": ObjectId ("5c1757f5f4e84940e0bd578c")
"name": "bbb"
Pwd: 321
Birthday: ISODate ("1999-10-10T00:00:00Z")
}
{
"_ id": ObjectId ("5c177b84f4e84940e0bd578d")
"name": "suhaozhi"
"pwd": "suhaozhi"
"phone": [
{
"phone_num": "13333333333"
"type": "cmcc"
}
{
"phone_num": 155555555555
"type": "chinanet"
}
]
"type": "chinanet"
}
{
"_ id": ObjectId ("5c177ba1f4e84940e0bd578e")
"name": "suhaozhi"
"pwd": "su"
"phone": [
{
"phone_num": "13333333332"
"type": "cmcc"
}
{
"phone_num": 15655555555
"type": "cnnet"
}
]
}
{"_ id": ObjectId ("5c178a62b1d327866c98c9f7"), "x": "y"}
{
"_ id": ObjectId ("5c1f226c87756129d06d2718")
"username": "aaa"
"phone_num": "13333333333"
}
{
"_ id": ObjectId ("5c1f232587756129d06d2719")
"username": "bbb"
"phone_num": [
"123"
"456"
]
}
Query criteria:
If you are familiar with regular SQL data, you can better understand MongoDB conditional queries through the following table:
The similar statement in the operation format example RDBMS is equal to {:} db.col.find ({"by": "Rookie tutorial"}). Pretty () where by = 'Rookie tutorial' is less than {: {$lt:}} db.col.find ({"likes": {$lt:50}) .pretty () where likes
< 50小于或等于{:{$lte:}}db.col.find({"likes":{$lte:50}}).pretty()where likes 50大于或等于{:{$gte:}}db.col.find({"likes":{$gte:50}}).pretty()where likes >= 50 is not equal to {: {$ne:}} db.col.find ({"likes": {$ne:50}}) .pretty () where likes! = 50
AND conditional query:
The find () method of MongoDB can pass in multiple keys (key), each key separated by a comma, which is the AND condition of a regular SQL.
Example:
Db.col.find ({key1:value1, key2:value2}) .pretty ()
Or conditional query:
The MongoDB OR conditional statement uses the keyword $or and the syntax format is as follows:
> db.col.find (
{
$or: [
{key1: value1}, {key2:value2}
]
}
). Pretty ()
And is used in conjunction with or:
The following example demonstrates the combined use of AND and OR, similar to the regular SQL statement: 'where age
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.

The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about

The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r


A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from

Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope





 
             
            About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.