How to select value from MongoJS query output
Problem
I have Mongojs Query call:
db.users.find({username:"eleeist"},function(err, docs) {
console.log(docs);
});
The docs
variable looks like this in console output:
[ { _id: 4fee05662b17f88abbeb60b6,
username: 'eleeist',
password: 'test' } ]
I would like to display the password of the user eleeist
.
I tried docs.password
but get awful errors.
So how do I select values from the returned Query result?
Problem courtesy of: Eleeist
Solution
docs
is an array of documents, so to get the password of the first one you'd use docs[0].password
.
Solution courtesy of: JohnnyHK
Discussion
View additional discussion.