Mongodb 如何打印脚本的结果?
我有一个非常基本的脚本文件,我想运行它并输出它。内容如下:Mongodb 如何打印脚本的结果?,mongodb,Mongodb,我有一个非常基本的脚本文件,我想运行它并输出它。内容如下: var data = db.participants.aggregate( {$match: {survey: ObjectId("548f9d0329ce94df22731668")}}, {$group:{ _id: "answers.question", totals: {$sum: 1} } } ); printjson(data); 我
var data = db.participants.aggregate(
{$match: {survey: ObjectId("548f9d0329ce94df22731668")}},
{$group:{
_id: "answers.question",
totals: {$sum: 1}
}
}
);
printjson(data);
我尝试过加载('/path/to/script.js'),但它输出了大量信息,如下所示:
"_firstBatch" : [
{
"_id" : "answers.question",
"totals" : 18566
}
],
"_cursor" : {
"next" : function next() { [native code] },
"hasNext" : function hasNext() { [native code] },
"objsLeftInBatch" : function objsLeftInBatch() { [native code] },
"readOnly" : function readOnly() { [native code] }
},
"hasNext" : function () {
return this._firstBatch.length || this._cursor.hasNext();
},
"next" : function () {
if (this._firstBatch.length) {
// $err wouldn't be in _firstBatch since ok was true.
return this._firstBatch.pop();
}
else {
var ret = this._cursor.next();
if ( ret.$err )
我怎样才能只显示脚本的结果而不显示所有其他垃圾呢?您将返回一个
迭代器或光标
或:
data.forEach(printjson);
while (data.hasNext()) {
printjson(data.next());
}