I have 2 MongoDB collection with similar set of fields, let’s say:
First [ { name: “first”, surname: “second” } ]
Second [ { name: “unique”, surname: “unique” } ]
I want to have a possibility to query data from any of 2, like:
db.All.find({}) - should return [ { name: “first”, surname: “second” } , { name: “unique”, surname: “unique” } ]
So I found the createView function and tried the following:
db.createView('All', 'First', { $merge: { into: { db: "db", coll: "Second" } } })
but it says “The aggregation stage $merge in location 0 of the pipeline cannot be used in the view definition”.
So how can I achieve what I need and manage possible duplicates?
Looks like $lookup query can be used only for objects related to each other, so what should be “pipeline” param for such case?