node.js中的一个对象mongodb返回奇怪的对象

时间:2019-01-14 06:57:08

标签: node.js mongodb object

我正在Nodejs内的MondoDB中调用一个文档。我在Node.js中使用fineOne方法,并且我知道findOne不会返回游标,而是直接返回文档。这可以通过正常打印return函数的参数来显示。但是问题是,当我在参数上使用foreach方法时,我得到了许多其他对象属性,这些属性看起来像游标(不是,因为它没有counter()方法)。我想知道为什么如果我使用Object.keys()或什至使用for循环,都会得到这样的额外键。

谢谢

摘要:

我的mongodb中有以下对象:

> db.test.find().pretty()
{
        "_id" : ObjectId("5c37c2c59330361008a37ba0"),
        "uId" : ObjectId("5c37c28d9330361008a37b9f"),
        "tag" : true
}

当我在nodejs中找到对象并使用Promise时,会看到以下内容:

test.findOne({uId:my._id}).then(function(arg){
console.log(arg) // returns _id,uId and tag as I expect
Object.keys(arg).forEach(key => { console.log(key, arg[key]) }) //returns many strange things that behaves like a cursor

})

奇怪部分的输出:

$__ InternalCache {
  strictMode: true,
  selected: {},
  shardval: undefined,
  saveError: undefined,
  validationError: undefined,
  adhocPaths: undefined,
  removing: undefined,
  inserting: undefined,
  saving: undefined,
  version: undefined,
  getters: {},
  _id: 5c3c0ab365ceft76002c316u,
  populate: undefined,
  populated: undefined,
  wasPopulated: false,
  scope: undefined,
  activePaths:
     StateMachine {
     paths: { tag: 'init', _id: 'init', uId: 'init' },
     states:
      { ignore: {},
        default: {},
        init: [Object],
        modify: {},
        require: {} },
     stateNames: [ 'require', 'modify', 'init', 'default', 'ignore' ] },
  pathsToScopes: {},
  cachedRequired: {},
  session: undefined,
  ownerDocument: undefined,
  fullPath: undefined,
  emitter: EventEmitter { domain: null, _events: {}, _eventsCount: 0, _maxListeners: 0 },
  '$options': { skipId: true, isNew: false, willInit: true } }
isNew false
errors undefined
_doc { tag: true,
  _id: 5c3c0ab365ceft76002c316u,
  uID: 5c343225e44ce33343rgg616d }
$init true

0 个答案:

没有答案