Say i have two different documents in difference collections: product
and brand
.
Product
{
"_id" "527bf4cb41b8a817774d5124",
"name": "Foo",
"brand": "527bf4cb41b8a817774d5125"
}
Brand
{
"_id" "527bf4cb41b8a817774d5125",
"name": "Bar"
}
I want to automatically retrieve the brand document and embed it in the product document when i query the database. Obviously i can just query the database for the brand document after retrieving the product object, which would work fine. But can i do this in a smarter way, that does not require 2 queries? I can't seem to find a solution to this. Also i would like it to work if i find more than one document.
Edit:
I would like to end out with something like this:
{
"_id" "527bf4cb41b8a817774d5124",
"name": "Foo",
"brand": {
"_id" "527bf4cb41b8a817774d5125",
"name": "Bar"
}
}