Thursday, 1 November 2018

[Question] I have a mongodb query and i'm trying to match a specific object inside of an array but I keep getting back the entire array.

​Hello everybody. I am trying to use a query to get a specific object inside of the passwordData array. I have the two lines of code that i'm using but both of which give me back the entire array. Below I have the expected output that I want and what I am getting back. Any help would be greatly appreciated!! Thank you very much in advance!​db.text.find({"passwordData":{"$elemMatch": { "webpage": "nba" }}})​db.text.aggregate([ { "$match" : { "passwordData.webpage" : "nba" } } ]);Expected output is{"webpage" : "nba","username" : "username","password" : "password","email" : "email"},​output receiving.{"_id" : ObjectId("432894032"),"email" : "email@email.com","passwordData" : [{"webpage" : "nba","username" : "username","password" : "password","email" : "email"},{"webpage" : "mlb","username" : "username","password" : "password","email" : "email"},{"webpage" : "nfl","username" : "username","password" : "password","email" : "email"}]}

Submitted November 01, 2018 at 05:20PM by jyourman24

No comments:

Post a Comment