In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article will explain in detail what is the use of pipes in MongoDB. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.
Introduction of MongoDB Pipeline and examples of operators
An introduction
Pipes are commonly used in Unix and Linux to use the output of the current command as a parameter to the next command.
MongoDB's aggregation pipeline passes the results of the MongoDB document to the next after one pipe has finished processing. Pipe operations can be repeated.
Expression: processes the input document and outputs it. Expressions are stateless and can only be used to evaluate documents for the current aggregation pipeline, not other documents.
Here we introduce several operations commonly used in the aggregation framework:
$project: modify the structure of the input document. Can be used to rename, add, or delete fields, or to create calculation results and nested documents.
Match: used to filter data and output only documents that meet the criteria. Match uses MongoDB's standard query operation.
Limit: used to limit the number of documents returned by the MongoDB aggregation pipeline.
Skip: skips the specified number of documents in the aggregation pipeline and returns the remaining documents.
Unwind: splits an array type field in a document into multiple strips, each containing a value in the array.
$group: groups the documents in the collection and can be used to count the results.
$sort: sort the input documents and output them.
$geoNear: outputs ordered documents close to a geographic location.
Two pipe operator instance
1. $project instance
Db.article.aggregate ({$project: {title: 1, author: 1,}})
In this way, there are only _ id,tilte and author fields in the result. By default, the _ id field is included, and you can do this if you want not to include _ id:
Db.article.aggregate ({$project: {_ id: 0, title: 1, author: 1}})
2.$match instance
Db.articles.aggregate ([{$match: {score: {$gt: 70, $lte: 90}, {$group: {_ id: null, count: {$sum: 1}])
$match is used to get records with scores greater than 70, less than or equal to 90, and then send the eligible records to the next stage $group pipeline operator for processing.
3.$skip instance
Db.article.aggregate ({$skip: 5})
After being processed by the $skip pipeline operator, the first five documents are "filtered" out.
This is the end of this article on "what is the use of pipes in MongoDB". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.