anyone know how to return the document with only matched sub-document in javascript?
e.g. here is the database records:
[
{"name":"bestbuy",notes:["article IT", "article 2"]},
{"name":"microsoft",notes:["article IT", "another IT", "article 5"]},
{"name":"IBM",notes:["article 8", "article 9"]}
]
here is my query:
collection.find({"company.notes":/IT/}, function(err,result){})
result is:
[
{"name":"bestbuy",notes:["article IT", "article 2"]},
{"name":"microsoft",notes:["article IT", "another IT", "article 5"]},
]
but my expected result is:
[
{"name":"bestbuy",notes:["article IT"]},
{"name":"microsoft",notes:["article IT", "another IT"]}
]
any idea? thanks