Quantcast
Channel: CNode:Node.js专业中文社区
Viewing all articles
Browse latest Browse all 14821

【已解决】console.log打印的结果是 [Object], 怎么让其显示具体的值?,环境为express+mongoose

$
0
0

使用的express+mongoose

var commentSchema = new mongoose.Schema({
    goodId: {type: String},
    username: {type: String},
    content: {type: String},
    createTime: {type: Date},
    follow: []
});
router.get('/comment/:goodId', function (req, res, next) {
    var content = {goodId: req.params.goodId};
    commentModel.find(content).lean().exec(function (err, result) {
        if (err) {
            console.log(err);
            res.json({'status': 'err', 'info': '数据获取失败!'});
        } else {
            console.log(result);
            res.json({'status': 'ok', 'info': result});
        }
    });
});

console.log输出的结果:

[ { _id: 57f79e5e310aea056fe30710,
    goodId: '57f70900ebb75c03805d0015',
    username: 'aa',
    content: '盖楼第一层a',
    createTime: Fri Oct 07 2016 21:08:46 GMT+0800 (CST),
    follow: [],
    __v: 0 },
  { _id: 57f79e76310aea056fe30711,
    goodId: '57f70900ebb75c03805d0015',
    username: 'aa',
    content: '盖楼第一层a',
    createTime: Fri Oct 07 2016 21:08:46 GMT+0800 (CST),
    follow: [ [Object], [Object], [Object] ],
    __v: 0 } 

在mongo命令行中查询的结果:

> db.comments.find().toArray();
[
	{
		"_id" : ObjectId("57f79e5e310aea056fe30710"),
		"goodId" : "57f70900ebb75c03805d0015",
		"username" : "aa",
		"content" : "盖楼第一层a",
		"createTime" : ISODate("2016-10-07T13:08:46.562Z"),
		"follow" : [ ],
		"__v" : 0
	},
	{
		"_id" : ObjectId("57f79e76310aea056fe30711"),
		"goodId" : "57f70900ebb75c03805d0015",
		"username" : "aa",
		"content" : "盖楼第一层a",
		"createTime" : ISODate("2016-10-07T13:08:46.562Z"),
		"follow" : [
			{
				"createTime" : ISODate("2016-10-07T13:09:10.238Z"),
				"content" : "盖楼第二层bb",
				"username" : "bb"
			},
			{
				"createTime" : ISODate("2016-10-07T13:09:10.238Z"),
				"content" : "盖楼第二层bb",
				"username" : "bb"
			},
			{
				"createTime" : ISODate("2016-10-07T13:09:10.238Z"),
				"content" : "盖楼第二层bb",
				"username" : "bb"
			}
		],
		"__v" : 0
	}
]

数据插入操作都是没有问题的。现在获取到的result ( follow: [ [Object], [Object], [Object] ],) 传到客户端后,follow输出值完全就是空的。 求指导,怎么才能获取到follow的值?


Viewing all articles
Browse latest Browse all 14821

Latest Images

Trending Articles