为什么console.log()和调试器中的对象值不同?

时间:2017-07-31 02:10:45

标签: javascript node.js mongodb debugging

那么为什么对象的变量在调试器中是不同的 debugger picture

和控制台日志?我特别询问_id变量看起来非常不同!

在调试器中,我无法找到此部分:"597e874b52fba6324c9ac192"

[ { _id: 597e874b52fba6324c9ac192,
title: 'x',
author: 'z',
body: 'y',
date: 2017-07-31T01:26:35.533Z,
comments: [],
__v: 0 },
{ _id: 597e87660726ab322c303a8e,
title: 'x',
author: 'z',
body: 'y',
date: 2017-07-31T01:27:02.266Z,
comments: [],
__v: 0 },
{ _id: 597e8773c45264303c3fcf0b,
title: 'x',
...

这是我使用的节点JS代码:

function test() {

var mongoose = require('mongoose');
mongoose.connect("mongodb://localhost:27017/test");
var Schema = mongoose.Schema;

var blogSchema = new Schema({
    title: String,
    author: String,
    body: String,
    comments: [{body: String, date: Date}],
    date: {type: Date, default: Date.now},
    hidden: Boolean,
    meta: {
        votes: Number,
        favs: Number
    }
});

var Blog = mongoose.model('Blog', blogSchema);




    Blog.create({title: 'x', author: "z", body: "y"}, function (err, small) 
{
        if (err) return handleError(err);
        // saved!
    });
    var weirdResults;
    Blog.aggregate([
        {$match: {author: {$exists: true}}}
    ], function (err, results) {
        weirdResults = results;
        if (err) return next(err);
        console.log(weirdResults);
    });

}

test();

全部谢谢!

1 个答案:

答案 0 :(得分:0)

您可以使用_id.toString();

获取ID