Pregunta

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?

¿Fue útil?

Solución

docs is an array of documents, so to get the password of the first one you'd use docs[0].password.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top