node.js - Mongoose - get array-entry of subdocument -
i've document looks this:
{ "_id" : objectid("5979f7a3bdbfcb25e6c32b95"), "name" : "company 1", "address" : { "street" : "mainstreet 4", "plz" : 1010, "ort" : "vienna", "land" : "at" }, "status" : "active", "settings" : [ { "key" : "sett1", "value" : "val1" } ], "users" : [ { "firstname" : "mike", "lastname" : "bold", "username" : "miky123", "password" : "mypassword", "token" : "ab78ab99684ef664654a65468b86de64", "status" : "active", "role" : "admin", "settings" : [ { "key" : "e1", "value" : "w1" }, { "key" : "e2", "value" : "w2" } ] } ] }
i want retrieve password-value can verify it. tried following code value:
company.findone({"users.username": req.body.username}, {"users.username.$": 1},function(err, user){ res.json(user); });
by using projection operator $ subset of document:
{ "_id": "5979f7a3bdbfcb25e6c32b95", "users" : [ { "firstname" : "mike", "lastname" : "bold", "username" : "miky123", "password" : "mypassword", "token" : "ab78ab99684ef664654a65468b86de64", "status" : "active", "role" : "admin", "settings" : [ { "key" : "e1", "value" : "w1" }, { "key" : "e2", "value" : "w2" } ] } ] }
so i've tried password by:
console.log(user.users[0].password);
but there error-message:
typeerror: cannot read property '0' of undefined
do have idea how retrieve password-value?
thanks!
Comments
Post a Comment