gpt4 book ai didi

mongodb - 如何打印脚本的结果?

转载 作者:可可西里 更新时间:2023-11-01 10:29:57 24 4
gpt4 key购买 nike

我有一个非常基本的脚本文件,我想运行它并输出它。内容如下:

var data = db.participants.aggregate(
{$match: {survey: ObjectId("548f9d0329ce94df22731668")}},
{$group:{
_id: "answers.question",
totals: {$sum: 1}
}
}
);

printjson(data);

我试过执行 load('/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 )

我怎样才能只显示脚本的结果而不显示所有其他垃圾?

最佳答案

您将返回一个IteratorCursor

http://docs.mongodb.org/manual/tutorial/iterate-a-cursor/

data.forEach(printjson);

或者:

while (data.hasNext()) {
printjson(data.next());
}

关于mongodb - 如何打印脚本的结果?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27640569/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com