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

MongoDB query how to output only part of the field content

2025-04-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

For example, the collection test has three columns id,url and data. Now we only want to output the id and url fields, which can be looked up as follows:

> db.test.find ({}, {id: 1, url: 1})

{"_ id": ObjectId ("5ad8a51bb5cec3000b17f39d"), "url": "http://info.zjktx.cn/urlsearch.php?info_flag=6&url=915ad2673221b5ab17ba29e24d00efc3"}

{"_ id": ObjectId ("5ad8a51bb5cec3000b17f39e"), "url": "http://mp.weixin.qq.com/s?__biz=MzIwOTY0NjY5NA==&mid=2247487505&idx=3&sn=8bdfc5b35eaa5eb7d2dbc2ff6247bf06&chksm=9771f518a0067c0e982d834821f9a44b7eea39f60cff8d50886175bbe1c93b27c70a8af9bfd9&scene=0#rd"}

{"_ id": ObjectId ("5ad8a51bb5cec3000b17f39f"), "url": "http://weibo.com/6432427115/GcR5t3Fh9"}

{"_ id": ObjectId ("5ad8a51bb5cec3000b17f3a0"), "url": "http://weibo.com/6503912228/GcR5ftPt7"}

{"_ id": ObjectId ("5ad8a51bb5cec3000b17f3a1"), "url": "http://mp.weixin.qq.com/s?__biz=MzU1NzE3MTEzOQ==&mid=2247486132&idx=7&sn=e031435df54cc5c6dcbdab4136c73222&chksm=fc38a218cb4f2b0e0b581ea5d7ef13f95d29321b385fe51137c8cd102b715ebfb75c284aacb0&scene=0#rd"}

{"_ id": ObjectId ("5ad8a51bb5cec3000b17f3a2"), "url": "http://mp.weixin.qq.com/s?__biz=MzAxOTMxMTAxOA==&mid=2650490009&idx=2&sn=020a9d674e4f48da10f3ed376bdda67f&chksm=83c7145cb4b09d4a153515ef56755098bccfbca92f7fb379621ffbe4177fc8431181a2d1f2cc&scene=0#rd"}

{"_ id": ObjectId ("5ad8a51bb5cec3000b17f3a3"), "url": "http://mp.weixin.qq.com/s?__biz=MzI0NTU3NDY1NQ==&mid=2247487947&idx=1&sn=0daadc7945dd56fa7f1c7c61557646ed&chksm=e94d2f5bde3aa64dc6578e1ce9997c5cbe57fc0500222dd9939da33877168afb3297045a50f8&scene=0#rd"}

{"_ id": ObjectId ("5ad8a51bb5cec3000b17f3a4"), "url": "http://weibo.com/ttarticle/p/show?id=2309614230624788536034"}

{"_ id": ObjectId ("5ad8a51bb5cec3000b17f3a5"), "url": "http://mp.weixin.qq.com/s?__biz=MzA5ODU0NzQ4OA==&mid=2649879715&idx=1&sn=5bdf0a2ca64b51df037252da73fe9d1c&chksm=888ab6ecbffd3ffa97bc454aef5e490eb8c4d5bd79e7dd61c833107dd907e3b7b6600bb7d111&scene=0#rd"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3a6"), "url": "http://www.qddtj.com/qdtj/961445.html"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3a7"), "url": "http://weibo.com/3078765485/GcQPzAWxR"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3a8"), "url": "http://weibo.com/1981850854/GcJ0KkXuz"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3a9"), "url": "http://weibo.com/2824592185/GcQQ9Dpu4"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3aa"), "url": "http://weibo.com/6456176195/GcQR69zDX"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3ab"), "url": "http://weibo.com/5996334075/GcR3UrMgN"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3ac"), "url": "http://weibo.com/3802294663/GcR5LDlyR"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3ad"), "url": "http://weibo.com/2428661490/GcQZL45qh"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3ae"), "url": "http://weibo.com/1762661765/GcR0LrC9O"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3af"), "url": "http://weibo.com/6135218321/GcQH544Rs"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3b0"), "url": "http://weibo.com/5996334075/GcR3OewDh"}

Type "it" for more

Note: the first parameter is the query condition, and an empty parameter represents the query for all

/ / if you do not want a field, you can use the method of excluding fields

For example, exclude the contents of the data field:

> db.test.find ({}, {data: 0})

{"_ id": ObjectId ("5ad8a51bb5cec3000b17f39d"), "url": "http://info.zjktx.cn/urlsearch.php?info_flag=6&url=915ad2673221b5ab17ba29e24d00efc3"," error: "BSON document too large (25962119 bytes)-the connected server supports BSON document sizes up to 16793598 bytes."}

{"_ id": ObjectId ("5ad8a51bb5cec3000b17f39e"), "url": "http://mp.weixin.qq.com/s?__biz=MzIwOTY0NjY5NA==&mid=2247487505&idx=3&sn=8bdfc5b35eaa5eb7d2dbc2ff6247bf06&chksm=9771f518a0067c0e982d834821f9a44b7eea39f60cff8d50886175bbe1c93b27c70a8af9bfd9&scene=0#rd"," web_url ":" http://info.zjktx.cn/urlsearch.php?info_flag=6&url=f570e117571609aa0e69f141c35bc97e"}

{"_ id": ObjectId ("5ad8a51bb5cec3000b17f39f"), "url": "http://weibo.com/6432427115/GcR5t3Fh9"}

{"_ id": ObjectId ("5ad8a51bb5cec3000b17f3a0"), "url": "http://weibo.com/6503912228/GcR5ftPt7"}

{"_ id": ObjectId ("5ad8a51bb5cec3000b17f3a1"), "url": "http://mp.weixin.qq.com/s?__biz=MzU1NzE3MTEzOQ==&mid=2247486132&idx=7&sn=e031435df54cc5c6dcbdab4136c73222&chksm=fc38a218cb4f2b0e0b581ea5d7ef13f95d29321b385fe51137c8cd102b715ebfb75c284aacb0&scene=0#rd"," web_url ":" http://info.zjktx.cn/urlsearch.php?info_flag=6&url=b39d555be6291870b4ec8b536e1f4657"}

{"_ id": ObjectId ("5ad8a51bb5cec3000b17f3a2"), "url": "http://mp.weixin.qq.com/s?__biz=MzAxOTMxMTAxOA==&mid=2650490009&idx=2&sn=020a9d674e4f48da10f3ed376bdda67f&chksm=83c7145cb4b09d4a153515ef56755098bccfbca92f7fb379621ffbe4177fc8431181a2d1f2cc&scene=0#rd"," web_url ":" http://info.zjktx.cn/urlsearch.php?info_flag=6&url=12649de899b18e864e6b708b422dd159"}

{"_ id": ObjectId ("5ad8a51bb5cec3000b17f3a3"), "url": "http://mp.weixin.qq.com/s?__biz=MzI0NTU3NDY1NQ==&mid=2247487947&idx=1&sn=0daadc7945dd56fa7f1c7c61557646ed&chksm=e94d2f5bde3aa64dc6578e1ce9997c5cbe57fc0500222dd9939da33877168afb3297045a50f8&scene=0#rd"," web_url ":" http://info.zjktx.cn/urlsearch.php?info_flag=6&url=54de9666bbd2cf523e6c2ea19ca0c324"}

{"_ id": ObjectId ("5ad8a51bb5cec3000b17f3a4"), "url": "http://weibo.com/ttarticle/p/show?id=2309614230624788536034"}

{"_ id": ObjectId ("5ad8a51bb5cec3000b17f3a5"), "url": "http://mp.weixin.qq.com/s?__biz=MzA5ODU0NzQ4OA==&mid=2649879715&idx=1&sn=5bdf0a2ca64b51df037252da73fe9d1c&chksm=888ab6ecbffd3ffa97bc454aef5e490eb8c4d5bd79e7dd61c833107dd907e3b7b6600bb7d111&scene=0#rd"," web_url ":" http://info.zjktx.cn/urlsearch.php?info_flag=6&url=c151dbab5c3caae7df038930e4019d67"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3a6"), "url": "http://www.qddtj.com/qdtj/961445.html"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3a7"), "url": "http://weibo.com/3078765485/GcQPzAWxR"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3a8"), "url": "http://weibo.com/1981850854/GcJ0KkXuz"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3a9"), "url": "http://weibo.com/2824592185/GcQQ9Dpu4"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3aa"), "url": "http://weibo.com/6456176195/GcQR69zDX"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3ab"), "url": "http://weibo.com/5996334075/GcR3UrMgN"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3ac"), "url": "http://weibo.com/3802294663/GcR5LDlyR"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3ad"), "url": "http://weibo.com/2428661490/GcQZL45qh"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3ae"), "url": "http://weibo.com/1762661765/GcR0LrC9O"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3af"), "url": "http://weibo.com/6135218321/GcQH544Rs"}

{"_ id": ObjectId ("5ad8a51cb5cec3000b17f3b0"), "url": "http://weibo.com/5996334075/GcR3OewDh"}

Type "it" for more

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: 205

*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

Wechat

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

12
Report