简体   繁体   English

节点js:Mongo DB性能$ in

[英]Node js: Mongo DB performance $in

I have a collection with 1121547 documents and I have to 5014 ids to search between these documents. 我有一个包含1121547个文档的集合,我必须有5014个ID在这些文档之间进行搜索。 Is it better to do a query with the $in operator, find its cursor and then go through the registries with eachAsync or Is it better do a for a loop in the Ids searching one by with find? 使用$ in运算符执行查询,找到其游标,然后使用eachAsync遍历注册表,还是在ID中使用find查找一个循环更好?

Thanks for the help. 谢谢您的帮助。

I would suggest you use $in for the search. 我建议您使用$ in进行搜索。 - If you do find() for each id then you will be processing the documents at Mongo as well as in your code. -如果您确实为每个ID找到find(),那么您将在Mongo以及您的代码中处理文档。 But in $in they are processed at Mongo. 但是在$ in中它们在Mongo中进行处理。 - Second point is all the operations like find() are scan methods they will look for the match in all documents unless you do indexing. -第二点是,所有操作(如find())都是扫描方法,除非您进行索引编制,否则它们将在所有文档中寻找匹配项。 so make sure the Ids that you are searching are indexed. 因此,请确保对要搜索的ID进行索引。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM