SQL 'UNION ALL' like implementation in MongoDB

前端 未结 3 1876
慢半拍i
慢半拍i 2021-01-23 01:53

There are two collections:

Sales

{
  \"_id\" : ObjectId(\"5ba0bfb8d1acdc0de716e839\"),
  \"invoiceNumber\" : 1,
  \"saleDate\" : ISODate(\"2018-09-01T00:         


        
3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-23 02:42

    I dont think so that you can perform a union on 2 different collections in mongodb.

    However you can get data from both collections using q.all and afterwards make a union from them using your own function or may be third party module like lodash.

    The only way you can perform union in mongodb is as mentioned here. https://docs.mongodb.com/manual/reference/operator/aggregation/setUnion/

提交回复
热议问题