I am dealing with a JSON document (found in mongolab):
{
"_id": {
"$oid": "566e8673eb862d165fef7171"
},
"street": "Dizingof",
"buildingNumber": 33,
"apartmentNumber": 63,
"beds": 3,
"owner": {
"_id": {
"$oid": "564374944cb813541afc193a"
},
"local": {
"password": "$2a$08$PtZrvLY7MWSi44gMDSjLJ.u4x.IOXIkRFZYfQhAwt.5vSIXpCYjX6",
"email": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d9aab6b4bcbcb4b8b0b599beb4b8b0b5f7bab6b4">[email protected]</a>"
},
"__v": 0
}
}
The schema defines the owner
field as:
owner : {
type: Schema.ObjectId,
ref: 'User'
}
However, when I make an http.get
request to fetch the listing, the returned data is missing the owner
field:
{
"_id": "566e8673eb862d165fef7171",
"street": "Dizingof",
"buildingNumber": 33,
"apartmentNumber": 63,
"beds": 3,
"imagesAndCount": [],
"UsersAndQuestions": []
}
I need access to the owner
field for HTML document manipulations but it's not there. Why could this be happening?
For reference, here is the relevant GET route in routes.js
:
app.get('/api/listing/:street/:buildingNumber/:apartmentNumber', function (req, res) {
Listing.findOne(
{
"street": req.params.street,
"buildingNumber": req.params.buildingNumber,
"apartmentNumber": req.params.apartmentNumber
}
, function (err, listing) {
if (err) { return next(err); }
res.json(listing);
});
});
Additionally, I populated the owner
field like this:
var myUser = db.users.findOne()
db.listings.insert({"street" : "Dizingof", "buildingNumber" : 33, "apartmentNumber" : 63, "beds": 3, "owner": myUser})