Goodmorning, I have the oddest thing. I hope someone can help me with this.
I'm fetching data from MongoDB (via Mongoose) Very simple result
{
reqts: 1469468008496
}
I am trying to access the property reqts
It's however undefined. But the result above is very clear about it's existence.
What I am doing is the following
// This gives me the above result, but doing data.reqts gives me nothing.
Couple.findOne().sort('-reqts').select('reqts -_id').exec(function(err, item) {
var data = item
response.json(data)
});
This gives me the object I mentioned before. If I do:
var data = item.reqts
It gives me nothing in return (response is empty).
Hope someone can help me with this. Thanks!
UPDATED: I am now writing out to console too.
Couple.findOne().sort('-reqts').select('reqts -_id').exec(function(err, data) {
if (err) { response.status(500).json({error: err}) }
else {
console.log(typeof data)
console.log(data)
console.log(data.reqts)
response.json(data)}
});
This is what it writes to console.
object
{ reqts: 1469468008496 }
undefined
UPDATED:
This seems to explain it: Dot operator not fetching child properties of a Mongoose Document object