当前位置:网站首页>Mongodb - $match operation of aggregation pipeline
Mongodb - $match operation of aggregation pipeline
2022-04-22 03:38:00 【Blog of Xiaozhi】
Catalog
One 、$ match Overview
- $ match Used to filter documents , After that, we can aggregate the document subsets ,$ match You can use all the regular query operators except geospatial , In practical application, try to $ match Put it in front of the pipe . This has two advantages : First, it can quickly filter out unnecessary documents , To reduce the workload of the pipeline ; The second is if it is executed before projection and grouping $match, Query can use index .
- When screening pipeline operation and other pipeline operations cooperate , Try to put it at the beginning , This can reduce the number of documents to be operated by subsequent pipeline operators , Improve efficiency .
Two 、 Data preparation
-
Prepare the dataset , Execute the script
var tags = ["nosql","mongodb","document","developer","popular"]; var types = ["technology","sociality","travel","novel","literature"]; var books=[]; for(var i=0;i<50;i++){ var typeIdx = Math.floor(Math.random()*types.length); var tagIdx = Math.floor(Math.random()*tags.length); var tagIdx2 = Math.floor(Math.random()*tags.length); var favCount = Math.floor(Math.random()*100); var username = "xx00"+Math.floor(Math.random()*10); var age = 20 + Math.floor(Math.random()*15); var book = { title: "book-"+i, type: types[typeIdx], tag: [tags[tagIdx],tags[tagIdx2]], favCount: favCount, author: { name:username,age:age} }; books.push(book) } db.books1.insertMany(books);
3、 ... and 、 Of polymerization pipeline $ match The operation sample
-
Inquire about books1 Data in the collection
> db.books1.find()
-
Inquire about books1 Collection type Field is technology All data for
db.books1.aggregate([{ $match:{ type:"technology"}}])
版权声明
本文为[Blog of Xiaozhi]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220332561067.html
边栏推荐
- Socket to do a simple network sniffer
- C language constant, string, escape character, initial level of annotation
- College English vocabulary analysis Chinese University MOOC Huazhong University of science and technology
- Computer wechat built-in browser turns on debugging mode
- Take a look at this guide when the Hackathon competition is going on
- TP5在制作二维码
- JDBC uses precompiling to execute DQL statements, and the output is placeholder content. Why?
- Xiaomi and zhiting's smart cameras protect your family privacy
- 查看应用程序内存使用情况
- Full summary of 18 tax categories of tax law with memory tips
猜你喜欢

MongoDB——聚合管道之$project操作

百度离线地图研发--laravel框架

Finition musicale de guitare

php. Ini configuration

2022-04-21:给定一个包含 [0,n) 中不重复整数的黑名单 blacklist, 写一个函数从 [0, n) 中返回一个不在 blacklist 中的随机整数, 对它进行优化使其尽量少调用系

使用supervisor管理laravel队列 - 配置文件supervisord.conf

How to restrict students in the computer room, get rid of the control of teachers and realize free internet access
![[server data recovery] a data recovery case in which multiple hard disks of server raid6 are offline successively](/img/4c/5fe2e4ca3596c8df86e2e08f4bfbac.jpg)
[server data recovery] a data recovery case in which multiple hard disks of server raid6 are offline successively

On August 16, 2021, a bug in Zhengfang educational administration system was accidentally found

Learning neural network drawing Matplotlib
随机推荐
Solution | fast intercom dispatching system: efficient cooperation
Understanding and analyzing log files
Redis persistence
Deep learning and image recognition: principle and practice notes day_ 18 (target detection)
Mysql8 hard disk version installation configuration
隊列使用問題總結 queue:work和queue:listen的區別
Collection thread safety
AI video cloud vs narrowband HD, who is the darling of the video era
[leetcode daily question] 824 Goat Latin
Zabbix5 series - making topology map (XIII)
vscode 打造 shell 使用
Error report: modulenotfounderror: no module named 'Astra‘
These good works of finclip hacker marathon competition, come and have a look
MNIST recognition through back propagation
An article gives you a preliminary understanding of the basic knowledge of C language operators
Implementation of small cases
The mountain is high and the road is far away, fearing no danger
Baidu offline map research and development -- laravel framework
go gin框架配置日志输出到文件
Unittest unit test (I)