Mongoose returns weird object
Mongoose v5.0.2
After using the find method it returns an object like this
{
"$__": {
"strictMode": true,
"selected": {},
"getters": {},
"_id": {
"_bsontype": "ObjectID",
"id": {
"0": 90,
"1": 111,
"2": 10,
"3": 129,
"4": 118,
"5": 190,
"6": 92,
"7": 11,
"8": 116,
"9": 21,
"10": 108,
"11": 7
}
},
"wasPopulated": false,
"activePaths": {
"paths": {
"password": "init",
"email": "init",
"name": "init",
"_id": "init",
"__v": "init"
},
"states": {
"ignore": {},
"default": {},
"init": {
"_id": true,
"name": true,
"password": true,
"email": true,
"__v": true
},
"modify": {},
"require": {}
},
"stateNames": [
"require",
"modify",
"init",
"default",
"ignore"
]
},
"pathsToScopes": {},
"emitter": {
"domain": null,
"_events": {},
"_eventsCount": 0,
"_maxListeners": 0
},
"$options": true
},
"isNew": false,
"_doc": {
"_id": {
"_bsontype": "ObjectID",
"id": {
"0": 90,
"1": 111,
"2": 10,
"3": 129,
"4": 118,
"5": 190,
"6": 92,
"7": 11,
"8": 116,
"9": 21,
"10": 108,
"11": 7
}
},
"name": "melvin",
"password": "test",
"email": "test",
"__v": 0
},
"$init": true
}
How to get rid of other property? and just return the name, password email and id.
Mongoose documents are pretty sophisticated objects, but you should be able to just call doc.toObject() to convert it to a POJO. How are you printing this output?
yeah we can use the doc.toObject().
How are you printing this output?
I found another issue similar on how I print this. I use routing controllers and I guess it is because of the class-transformer. here's the link https://github.com/typestack/routing-controllers/issues/153
So what's the takeaway here? Can you use doc.toObject() or is there another issue here?
So what's the takeaway here?
hmm it is not an issue of mongoose, I think we can close this now. Thanks @vkarpov15
Can you use doc.toObject() or is there another issue here?
yup we can use doc.toObject(), no other issue here. we can close this now
https://mongoosejs.com/docs/tutorials/lean.html worked for me