Finding all documents with field = yes

I have been searching, and I find it rather complicated to get this done, how do I find all documents where the field = “yes” ? Is the result shown in a array of documents?

ps. I find it strange that I can’t use the db.collection.find({active: yes}).then(result=>{ console.log(result); });
So, I cannot use a promise there, I am confused… how do I get these results?

I want to update all fields on a function with a timer, so that e.g. every 5 seconds it decreases 5000…
So every 5 seconds it queries and verifies the fields…

(its a timer function)


I don’t understand what exactly you want here. please check this example playground: Mongo playground. Isn’t that what you want? the query is simple.

next, “find” is a cursor method. you need to understand what a cursor is, and how to use it. Cursor Methods — MongoDB Manual. its use in a driver changes, so also check the manuals of whichever driver you use.

alternatively, you can use aggregations for multi-step queries (pipeline). Aggregation Operations — MongoDB Manual

querying and updating are two separate things. timers are the easy parts. you need to decide how you update your documents.

Anyways, you seem pretty new to MongoDB. I suggest you visit MongoDB University. M001 and M121, along with M220xx (select language) and M320 would be nice for starters. (Or follow the “new university” link for a bit more guided paths)
Free MongoDB Official Courses | MongoDB University

1 Like