[英]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.