node.js - Mongoose : How to display in the console the content of an Object typed Mixed?

标签 node.js mongodb mongoose

具有以下数据:

lines: [{ line: [12, 'Joe'] }, { line: [14, 'John'] }, { line: [6, 'Walter'] }, { line: [3, 'William'] }, { line: [18, 'Bill'] }, { line: [22, 'Albert'] }]

模型

const Schema = mongoose.Schema;
const Line = new Schema({
  line: [Schema.Types.Mixed]
});
const TableSchema = new mongoose.Schema({
  lines: [Line]
});

当我保存然后在控制台中显示集合时,我得到: console.log

res.body: { __v: 0,
  _id: '590437516c71e30ee4ddcf4e',
  lines: 
   [ { _id: '590437516c71e30ee4ddcf54', line: [Object] },
     { _id: '590437516c71e30ee4ddcf53', line: [Object] },
     { _id: '590437516c71e30ee4ddcf52', line: [Object] },
     { _id: '590437516c71e30ee4ddcf51', line: [Object] },
     { _id: '590437516c71e30ee4ddcf50', line: [Object] },
     { _id: '590437516c71e30ee4ddcf4f', line: [Object] } ],

不应该吗?

   [ { _id: '590437516c71e30ee4ddcf54', line: [12, 'Joe']
   ...

为什么内部数组对象的内容没有完全显示?

感谢反馈

最佳答案

该对象对于 console.log() 来说嵌套得太深,它在幕后使用 util.inspect()检查物体。该函数的默认递归深度为 2。

要将深度增加到“无穷大”,您可以使用以下命令:

console.log(util.inspect(data, { depth : null }));

或者,您可以使 console.log() 输出 JSON:

console.log('%j', data);

关于node.js - Mongoose : How to display in the console the content of an Object typed Mixed?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43692748/

相关文章:

node.js - Mongoose-mongoDB 高级查询连接

django - django <-> 应用程序服务器(node.js)之间的通信方法?

javascript - 我无法编辑 Selenium Standalone 上的超时

javascript - 如何在同一个函数中使用不同的 uri

arrays - 如何使用吗啡过滤mongo文档中的嵌入数组

node.js - Mongoose findOne 返回空数组字段

node.js - MongoDB/Mongoose $pull(删除)子文档不起作用

javascript - 查找 MongoDB 数据库中的更改

javascript - 2 Collection.find 超出了最大调用堆栈大小

save - 如何跳过 Mongoose 预保存钩子(Hook)?