![](/img/trans.png)
[英]Why is 'this' undefined in the debugger but printable in a console.log?
[英]Why object values are different in console.log() and in debugger?
和控制台日志? 我正在特别查询看起来很不同的_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();
谢谢大家!
您可以使用_id.toString();
获得ID _id.toString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.