登录
注册
node.js 学习社区
mongoose如何获取查询结果

WuBinCPP

2020-01-30 20:57

我通过以下指令查询一条信息,但是返回的结果附带了一堆用不到的信息。

请问mongoose如何获取到干净一点的对象?

查询代码:

MyModel.findOne({}, function (err, docs) { console.log(docs)})

mongoose查询返回的结果如下:

model {

'$__': InternalCache {

strictMode: true,

selected: {},

shardval: undefined,

saveError: undefined,

validationError: undefined,

adhocPaths: undefined,

removing: undefined,

inserting: undefined,

version: undefined,

getters: {},

_id: 5e32c982c504e406ecac3291,

populate: undefined,

populated: undefined,

wasPopulated: false,

scope: undefined,

activePaths: StateMachine {

paths: [Object],

states: [Object],

stateNames: [Array]

},

pathsToScopes: {},

ownerDocument: undefined,

fullPath: undefined,

emitter: EventEmitter {

_events: [Object: null prototype] {},

_eventsCount: 0,

_maxListeners: 0

},

'$options': true

},

isNew: false,

errors: undefined,

_doc: {

__v: 0,

height: 1650,

age: 53,

name: '松江',

_id: 5e32c982c504e406ecac3291

},

'$init': true

}




回复 · 1

  • 返回的结果集经过加工了,需要一个参数放在options 里面 rawResult:true 或者raw:true ,自己查查手册

    0

发表回复

你可以在回复中 @ 其他人