Object.keys() returns unexpected keys on MongoDB object from collection

Viewed 11435

Working with a strange problem here. This is an array of objects which is pulled from mongodb and passed into the following function.

I tried the following 3 logs sequentially within the forEach on the array pulled from the database:

  • e (the object element within the array) which returns correctly. as you can see all the properties (keys) exist:
{ paid: false,   
  hotelWebsite: 'www.testing.com',   
  _id:5951848a24bb261eed09d638,   
  hotelAddress: '123 easy street',
...etc }
  • console.log(Object.keys(e)) is returning things that are not the keys...
[ '__parentArray',
  '__parent',
  '__index',
  '$__',
  'isNew',
  'errors',
  '_doc',
  '$init' ]
  • and finally:
for(key in e){
    console.log(key);
}

which returns an absolute mess of data, part of which DOES contain the actual keys of the object:

__parentArray
__parent
__index
$__
isNew
errors
_doc
$init
id
_id
hotelWebsite
hotelAddress
hotelNumber
hotelName
courseCost
courseDate
courseState
courseCity
courseName
paid
studentComments
studentEmail
studentPhone
studentCountry
studentZip
studentState
studentCity
studentAddress
studentCompany
studentName
schema
constructor
$__original_remove
remove
_pres
_posts
$__original_validate
validate
toBSON
markModified
populate
save
update
inspect
invalidate
$markValid
$isValid
ownerDocument
$__fullPath
parent
parentArray
on
once
emit
listeners
removeListener
setMaxListeners
removeAllListeners
addListener
$__buildDoc
init
$hook
$pre
$post
removePre
removePost
_lazySetupHooks
set
$__shouldModify
$__set
getValue
setValue
get
$__path
unmarkModified
$ignore
modifiedPaths
isModified
$isDefault
isDirectModified
isInit
isSelected
isDirectSelected
$__validate
validateSync
$__reset
$__dirty
$__setSchema
$__getArrayPathsToValidate
$__getAllSubdocs
$__handleReject
$toObject
toObject
toJSON
toString
equals
execPopulate
populated
depopulate

And a relevant sample of the code if needed:

studentsArray.forEach( (e, i) => {

        if(task === 'nameTag'){
            console.log(e);
            console.log(Object.keys(e));
            for(k in e){
                console.log(k);
            }
        }
....

I need access to the properties (keys) for further processing within the forEach function. I am very confused on what is causing this and have never run into this sort of issue before. For the record the objects exist, using a console.log(typeof e) it IS an object (not a data "string"). I can access the properties using the dot or bracket notation but NOT using Object.keys() or for (keys in obj).

Can anyone help me sort this out please?

1 Answers
Related