I am building up a side-project, below is a stripped down version of the dataset:
{
"_id": 1234,
"title": "A",
"inventory": [
{
"location":"1",
"barcodes": [1000, 1006, 1012]
},
{
"location":"2",
"barcodes": [1001, 1007, 1013]
}
]
},
{
"_id": 1235,
"title": "B",
"inventory": [
{
"location":"1",
"barcodes": [1002, 1008, 1014]
},
{
"location":"3",
"barcodes": [1003, 1009, 1015]
}
]
},
{
"_id": 1236,
"title": "C",
"inventory": [
{
"location":"2",
"barcodes": [1004, 1010, 1016]
},
{
"location":"3",
"barcodes": [1005, 1011, 1017]
}
]
}
The inventory array has a list of documents, among the fields in those documents is an array of Strings, no value in that barcodes array will be duplicated throughout any other document. The collection has a series of these documents. What I am trying to do is set up a find where I provide the barcode(s) I am searching for and only the parent document and the matching documents in the inventory array will be returned. For example, if I search for barcodes 1001 and 1011, the only information to be returned should be
{
"_id": 1234,
"title": "A",
"inventory": [
{
"location":"2",
"barcodes": [1001, 1007, 1013]
}
]
},
{
"_id": 1236,
"title": "C",
"inventory": [
{
"location":"3",
"barcodes": [1005, 1011, 1017]
}
]
}
I know how to do this with aggregations but I’m trying to use a basic find