I'm using nodejs and mongoose in my project and i'm trying to populate an array of object(truc in my case) using mongoose populate but i got an empty array in the truc attribute I dont know why :
function :
const getUserVehicles = async(id) =>{
return new Promise((resolve, reject) => {
User.findById(id)
.populate('truc')
.exec(function (err, item) {
if (err) return handleError(err);
console.log('The item is %s', item);
// prints "The author is Ian Fleming"
resolve(item)
});
})
}
response :
"verified": false,
"userType": "Individu",
"status": "Disponible",
"truc": [], --here's the empty array
"_id": "5d4435f57cd101243d1b48a6",
"email": "test125@gmail.com",
"createdAt": "2019-08-02T13:09:09.148Z",
"updatedAt": "2019-08-02T13:09:09.148Z"
User model :
.....
truc: [{ type: Schema.ObjectId, ref: 'Vehicle' }]
.....
could anyone help please ?