Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

How to select value from MongoJS query output

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.



This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

How to select value from MongoJS query output

×

Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription

×