lundi 2 mars 2015

js combining objects only returns an id

I am doing several finds in mongoose and then when I try to to combine the data it only displays the id and not the whole object. However, if I console.log() the object specifically it will display all of the contents.


Here are two of my finds in mongoose:



Project.find({ title: data.title }, function (err, projectObject) {
if (err || !projectObject) cb(err, null);

var project = new Object();;
for(var key in projectObject)
if (undefined !== projectObject[key])
project[key] = projectObject[key];

LocationService.selectLocations({ projects: [ project._id ] }, function (err, locations) {
if (err) cb(err, null);

searchCriteria = {};

if (locations)
for (var i in locations)
project.location.push(locations[i]);
});
});


If I now do a console.log(project) it will display:



{
'_id': 'ad5ffeb5a5a5fa763a64f3',
'title': 'Tested project',
'body': 'This is the content for the project.',
__v: 0,
'date_created': 'Wed Jan 07 2015 10:34:06 GMT-0600 (CST)',
'location':[
'ad5ffeb5a5a5fa763a64f4'
],
'moderator':[
'b041516116c16a1c5fb'
]
}


Now if I do console.log(project.location) this is what shows (off of the same object):



[
{
'_id': 'ad5ffeb5a5a5fa763a64f4',
'name': 'home',
'city': 'Columbia',
'state': 'MO',
'postcode': '65203',
'country': 'US',
'timezone': 'CST',
'__v': 0,
'geo':{
'type':'Point',
'coordinates':[
-92.339894,
38.962357
]
}
}
]


This is where I am confused because the object is there, but it only shows the id and not the whole object.


I am wondering if I am doing something wrong or even is there a better way to be doing this?


Aucun commentaire:

Enregistrer un commentaire