简体   繁体   English

如何在猫鼬中添加有关集合的元数据

[英]How to add metadata about a collection in mongoose

I have a script (node.js) which periodically ping (every 10 sec) a mongoose collection to see if there are new documments added. 我有一个脚本(node.js),该脚本会定期(每10秒)ping猫鼬集合,以查看是否添加了新文档。 I want the query to be as fast as possible. 我希望查询尽快。 Is it possible to write metadata about a collection? 是否可以编写有关集合的元数据?

For example: I would like to push the title of each new document in a (global) array for each new document inserted so the script will just have to read this array and erase it after: no need to go through all the documents and check if date > (now() - 10 sec). 例如:我想为插入的每个新文档将每个新文档的标题推送到(全局)数组中,因此脚本只需要读取该数组并在之后将其擦除即可:无需遍历所有文档并检查如果date>(now()-10秒)。

if you just want to now if the collection has changed you can run a count query: 如果您只是想现在更改集合,则可以运行count查询:

Query#count([criteria], [callback])

Specifying this query as a count query.

Parameters:

[criteria] <Object> mongodb selector
[callback] <Function>
Returns:

<Query> this

http://mongoosejs.com/docs/api.html#query_Query-count https://docs.mongodb.org/manual/reference/method/db.collection.count/ http://mongoosejs.com/docs/api.html#query_Query-count https://docs.mongodb.org/manual/reference/method/db.collection.count/

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

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