简体   繁体   中英

How to query several MongoDB collections at once?

For example, I have two collections A and B and I have a find() query per each collection with unrelated data to return. What I need is to combine these two query results and execute limit() and skip() operations. Executing these two queries sequentially is a pretty complex task.

I believe you can do something like that:

const [docs1, docs2] = await Promise.all([
      Model1.find().skip().limit().exec(),
      Model2.find().skip().limit().exec()
])

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