I have a test database, where 5:100 cardinality exist between Parent:Child entity.
I have used Parent document embedding in child document. A child document may associated with more than one parent document.
To search non-duplicated set of child documents by parent’s properties, I have used $group as mentioned below in query:
collection.aggregate([{“$match”:{“p_field”:{“$gte”:ranges1,“$lte”:ranges2}}},{“$unwind”:“$cs”},{“$group”:{“_id”:{“c_id”:“$cs.c_id”,“cfield”:“$cs.c_field”}}}])
Database size is approx 1.2GB., and wiredTigerCache is configured 11G. Even after that, I am getting Error :Exceed Memory for $group operation.
Is this correct? I don’t have a good test-case in front of me but I’m curious and the link doesn’t really seem to describe what you posted… Are you saying that DISTINCT would only select one row with “USA” if I had two columns with countries listed (say one for a Supplier and one for a Destination)?
Thank you steevej for your prompt response.
c_id is id of child document, and cfield is property of child document.
So, for every c_id, there is only one cfield associated.
Yes sir. It is analogous to supply relationship between supplier and product, where same supplier can supply multiple product , and same product can be supplied by multiple supplier.
And query something like find products supplied by supplier having rating between 2 to 5 .
So, query would be
collection.aggregate( [
{“$match”: {“rating”: { “$gte”: 2 ,“$lte”: 5 }}},
{“$unwind”:“$products”},
{“$group”:
{ “_id” : { “$ products.sku”, “products.name” } }
}])