且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Mongoose,子文档是对象而不是 json

更新时间:2023-12-04 12:57:22

所有的文档和子文档都是 JavaScript 中的对象.只是 console.log 在调用 util.inspect 时使用默认深度 2 来格式化您的文档以进行输出.您可以通过调用 util.inspect来输出文档的所有级别> 自己:

The all docs and subdocs are objects in JavaScript. It's just that console.log uses the default depth of 2 when calling util.inspect to format your document for output. You can output all levels of the document by calling util.inspect yourself:

var util = require('util');

hero.find({} ,{'deck' : {$elemMatch:{name:'Guard Tower'}}}, function(err, tower) {
    console.log(util.inspect(tower, false, null)); 
});