Batch multiple request

I use atlas data api REST api.
Is there any way i can batch multiple request with findOne or findMany on 1 request.
it will be fine if if only have 1 request but sometime i need to retrieve data on multiple collection
I know about aggregation can query that but my data doesn’t have relation.
I just want to group 2 or 3 findOne request to 1 .

Take a look at $unionWith. Basically, you do a $match for thr first find, then $unionWith for the other finds in the other collections.

@steevej hi Thank for your answer i try it and it working .
but it have a problem if one of multiple request have empty result i will not know what is empty.

sample union 2 collection Box and Fish but it only return data from Fish .

  pipeline: [
    { '$match': { _id: { '$oid': '64e21c2bfd2411163dde547f' } } },
    {
      '$unionWith': {
        coll: 'Fish',
        pipeline: [
          { '$match': { _id: { '$oid': '6486815f53f72d0e3c3c5cdb' } } }
        ]
      }
    }
  ]
}
1 Like

I just figure out how to do that with $faceit with the help of chatgpt

Now I looking for something to do multiple update by 1 aggregate but chatgpt say i can’t do that.
Is that correct ?

As a courtesy to other users of the forum it would be nice if you could publish the $facet implementation you came up with.

Ad Thanks Vance

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.