简体   繁体   中英

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. 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).

if you just want to now if the collection has changed you can run a count query:

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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