I'm debugging a NodeJS app where mongodb
is being used.
When I console.log
keys of a JS object (say booking
) using console.log( Object.keys(booking) )
statement, it prints:
[
'$__', 'isNew',
'errors', '_doc',
'$locals', '$op',
'$init'
]
But When I directly print the same object using console.log(booking)
statement, it prints:
{
_id: 5eb4fef797bf1e29986e333f,
user: 5eb413c78a84bc63f0ef83d4,
event: {
_id: 5eb4182c45d25b4c981a21ce,
title: 'Test Event',
description: 'bla bla bla',
price: 99.99,
date: 'Wed Jan 01 2020 05:45:00 GMT+0545',
creator: 5eb413c78a84bc63f0ef83d4,
__v: 0
},
createdAt: 2020-05-08T06:40:55.905Z,
updatedAt: 2020-05-08T06:40:55.905Z,
__v: 0
}
Now if you notice, some keys are missing both times I do console.log
. I have no idea what the hell is going on. WHY is that happening?
I'm also using mongoose
models. My code is like this:
Booking.findById({_id: args.bookingID}).populate('event').then(booking => {
console.log( booking )
console.log( Object.keys(booking) )
});
请询问您是否需要更多信息。
任何帮助将不胜感激 :)
First of all please mention which fields are missing in
console.log(booking)
Have you tried
console.log(JSON.stringify(booking))