Hello,
Couldn’t find a solution for MongoDB-like “$unwrap” functionality for the nested documents, can anybody help?
I have two documents with “nested” prices field (a document is a product with multiple nested vendor prices):
{
"_id": "1",
"name": "Product 1",
"prices": [
{
"vendor_id": 1,
"cost": 10,
},
{
"vendor_id": 2,
"cost": 20,
}
],
},
{
"_id": "2",
"name": "Product 2",
"prices": [
{
"vendor_id": 1,
"cost": 100,
},
{
"vendor_id": 2,
"cost": 200,
}
],
}
The search results query should return four documents, with each vendor price “unwinded” (injected into main product document):
{
"_id": "1XXXX",
"name": "Product 1",
"vendor_id": 1,
"cost": 10,
},
{
"_id": "1XXXX",
"name": "Product 1",
"vendor_id": 2,
"cost": 20,
},
{
"_id": "1XXXX",
"name": "Product 2",
"vendor_id": 1,
"cost": 100,
},
{
"_id": "1XXXX",
"name": "Product 2",
"vendor_id": 2,
"cost": 200,
}
The only idea for now, is to index each product-price pair as a separate document, but it creates extra data because product-specific fields like ‘name’ are duplicated in each product-price document.