Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to realize Field judgment in MongoDB

2025-01-17 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 field judgment 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.

Use "$exists" to determine whether a field exists, if set to true means it exists, and if it does not exist along with false.

Example: query information about parents personnel

> db.emp.find ({"parents": {"$exists": true}}) .pretty ()

{

"_ id": ObjectId ("599148bd0184ff511bf02b91")

"name": "Lin A"

"sex": "male"

"age": 22

"sal": 8000

"loc": "Beijing"

"course": [

"Chinese"

"Mathematics"

"English"

"Music"

"politics"

]

"parents": [

{

"name": "Lin A Father"

"age": 50

Job: the Peasant

}

{

"name": "Lin A Mother"

"age": 49

"job": "worker

}

]

}

Example: query information that does not have course personnel

> db.emp.find ({"course": {"$exists": false}}) .pretty ()

{

"_ id": ObjectId ("599108423268c8e84253be26")

"name": "Zhao Yi"

"sex": "male"

"age": 30

"sal": 1000

"loc": "Beijing"

}

You can use such queries to filter unwanted data. It is strongly recommended that the composition of the data be consistent.

After reading the above, do you have any further understanding of how to implement field judgment 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.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report