相关疑难解决方法(0)

Object.keys()从集合中返回MongoDB对象上的意外键

在这里处理一个奇怪的问题.这是一个从mongodb中提取并传递给以下函数的对象数组.

forEach从数据库中拉出的数组中依次尝试了以下3个日志:

  • e(正确返回的数组中的object元素).如您所见,所有属性(键)都存在:
{ paid: false,   
  hotelWebsite: 'www.testing.com',   
  _id:5951848a24bb261eed09d638,   
  hotelAddress: '123 easy street',
...etc }
Run Code Online (Sandbox Code Playgroud)
  • console.log(Object.keys(e)) 正在回归不是关键的东西......
[ '__parentArray',
  '__parent',
  '__index',
  '$__',
  'isNew',
  'errors',
  '_doc',
  '$init' ]
Run Code Online (Sandbox Code Playgroud)
  • 最后:
for(key in e){
    console.log(key);
}
Run Code Online (Sandbox Code Playgroud)

它返回绝对混乱的数据,其中一部分包含对象的实际键:

__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 …
Run Code Online (Sandbox Code Playgroud)

javascript mongoose node.js

10
推荐指数
1
解决办法
5386
查看次数

Mongoosejs .find 返回整个模型而不是文档

我在现有模型上运行 .find() 查询。我过去曾使用过此代码并且什么也没改变,但现在突然由于某种原因它不起作用。我在想 MongoDB 或 MongooseJS 已更新并且功能已更改。

var retrieve = function() {
  Repo.find({}, function(err, docs) {
    console.log(docs)
  })
};

retrieve();
Run Code Online (Sandbox Code Playgroud)

返回

[
  model {
    '$__': InternalCache {
      strictMode: true,
      selected: {},
      shardval: undefined,
      saveError: undefined,
      validationError: undefined,
      adhocPaths: undefined,
      removing: undefined,
      inserting: undefined,
      version: undefined,
      getters: {},
      _id: 5e02e91c908f0f086e737189,
      populate: undefined,
      populated: undefined,
      wasPopulated: false,
      scope: undefined,
      activePaths: [StateMachine],
      pathsToScopes: {},
      ownerDocument: undefined,
      fullPath: undefined,
      emitter: [EventEmitter],
      '$options': true
    },
    isNew: false,
    errors: undefined,
    _doc: {
      __v: 0,
      stars: 2, …
Run Code Online (Sandbox Code Playgroud)

javascript database mongoose mongodb node.js

3
推荐指数
2
解决办法
4012
查看次数

标签 统计

javascript ×2

mongoose ×2

node.js ×2

database ×1

mongodb ×1