我正在使用aggregate()
方法,并在游标中查找我正在使用代码
dbObjArray = new BasicDBObject[2]
dbObjArray[0]= cruxLevel
dbObjArray[1] = project
// dbObjArray[2] = out
List<DBObject> pipeline = Arrays.asList(dbObjArray)
if (!datasetObject?.isFlat && jsonFor != 'collection-grid') {
println '-------------------------------- inside if block bbb--------------------------------------'
output= dataSetCollection.aggregate(pipeline)
}else{
/*DBObject out = new BasicDBObject('$out':"datasetTemp");
def db = getDB()*/
println '-------------------------------- inside else block--------------------------------------'
AggregationOptions aggregationOptions = AggregationOptions.builder()
.batchSize(100)
.outputMode(AggregationOptions.OutputMode.CURSOR)
.allowDiskUse(true)
.build();
output = dataSetCollection.aggregate(project)
}
我收到以下错误。
com.mongodb.CommandFailureException:{“serverUsed”: “127.0.0.1:15847”,“errmsg”:“异常:管道元素0不是 对象“,”代码“:15942,”ok“:0.0}
我出错的地方请帮忙!
谢谢。
答案 0 :(得分:2)
def dbObjArray = new BasicDBObject[1]
dbObjArray[0]= project
List<DBObject> flatPipeline = Arrays.asList(dbObjArray)
AggregationOptions aggregationOptions = AggregationOptions.builder()
.batchSize(100)
.outputMode(AggregationOptions.OutputMode.CURSOR)
.allowDiskUse(true)
.build();
def cursor = dataSetCollection.aggregate(flatPipeline,aggregationOptions)