I'm new to Mongo, and I'm trying to retrieve specific data among several with same name from a find() query:
Let me explain-> Users is collection with following document:
"linkedaccounts": [
{
"accountname": "Rani Charan",
"accountnumber": "10815748690065",
"ifsc": "UTIB0001081",
"virtualid": "taran@xyz",
"_id": "571488b9720023940539959e",
"isDefaultReceiving": false,
"isDefaultFunding": false,
"isAppEnabled": false,
"aeba": false,
"accountsource": 0
},
{
"accountname": "Rani Singh",
"accountnumber": "01316366360080",
"virtualid": "ranisingh@xyz",
"_id": "571488b972002394053995a0",
"ifsc": "UTIB0000131",
"isDefaultReceiving": false,
"isDefaultFunding": true,
"isAppEnabled": true,
"aeba": false,
"accountsource": 0
},
{
"accountname": "Rani K Singh",
"accountnumber": "07916956560873",
"virtualid": "ranik@xyz",
"_id": "571488b9720023940539959f",
"ifsc": "UTIB0000791",
"isDefaultReceiving": true,
"isDefaultFunding": false,
"isAppEnabled": true,
"aeba": false,
"accountsource": 0
}
]
now i want to fetch account number and ifsc code where virtual id is "ranisingh@xyz" . i able to get some filtered data using this query:
db.users.find(
{"linkedaccounts.virtualid": "ranik@xyz"},
{_id: 0, 'linkedaccounts.accountnumber': 1,'linkedaccounts.ifsc': 1})
but in result i get all three accountsnumber and ifsc code . like this:-
{
"linkedaccounts" : [
{
"accountnumber" : "10815748690065",
"ifsc" : "UTIB0001081"
},
{
"accountnumber" : "01316366360080",
"ifsc" : "UTIB0000131"
},
{
"accountnumber" : "07916956560873",
"ifsc" : "UTIB0000791"
}
]}
so now i want to print only one accountnumber and ifsc code that beleongs "ranisingh@xyz".