Reputation: 17
following is my mongodb User document___
{ "name":"steve", "email": "[email protected]", "password": "tnvddcnd", "cards": [{ "tags": "card", "user": "steve", "bank": "bank of sheild", "cardNo": 5152655, "expiry": "2/21/2022", "cvv": 512, "pin": 5155 }, { "tags": "card", "user": "ironman", "bank": "stark bank", "cardNo": 56555, "expiry": "2/21/2028", "cvv": 256, "pin": 6666}] }
for every user ,I have cards store in array of cards. What i wanted is to find a user by email id which will come as query and then get the cards for that user
Upvotes: 0
Views: 180
Reputation: 184
I suppose you use mongodb-driver
// find user by email and return cards:
user = await db.collection('User').findOne({email: "[email protected]"}, {projection: {cards: 1}});
// cards
user.cards
Upvotes: 1