和控制台日志?我特别询问_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();
全部谢谢!
答案 0 :(得分:0)
您可以使用_id.toString();