I am new to MongoDB. I would like to know how can we filter/retrive an object inside an array of multiple objects based on certain fields?
for eg. I want to retrive only Object: 0 from Transaction array referencing fields like ProviderName, TimeStamp. How can i do that?
Hi. You may need to use ‘.’ dot to reference a particular field either in an embedded document or array. For example: db.collection.find({“Employee.Transactions.ProviderName”: “yourSearchCriterion”}). This search approach only returns the first document that matches.
I don’t want it to return the document. But only one object inside an array based on searching multiple fields.
In that case, you can also use projection in the find query, e.g. db.collection.find({}, {“_id”:0, “Employee.Transactions.ProviderName” : 1}).
This page will give you more details about projection of fields from embedded documents and array:
Please provide sample documents we can import in our environment.
Please provide exact values for the query. For example, transactions.0 and transactions.1 both refers to ProviderName:TABAPAY, do you want both of only the first one.
Please provide a sample of the output document(s) that you want.
We cannot work out of you image and descriptions.