当前位置:首页 > 编程笔记 > 正文
已解决

Mongodb3.4升级高版本mongoTemplate.executeCommand报错The cursor option is required

来自网友在路上 11178117提问 提问时间:2023-11-21 20:01:09阅读次数: 117

最佳答案 问答题库1178位专家为你答疑解惑

mongodb3.4版本升级高版本后mongoTemplate.executeCommand的方式执行的语句报错,如:在这里插入图片描述

Document document = mongoTemplate.executeCommand(pipl)

错误信息:The cursor option is required
高版本的需要cursor选项参数,官网这么写的:
在这里插入图片描述
修改语句加入cursor: cursor: {}, 里面也可以写参数,不写应该是默认。
在这里插入图片描述
这时候返回的Document是一个cursor,里面没有原来的result了。
里面是这些内容:
在这里插入图片描述
我这里firstBatch里面就是对应之前的result结果。如果结果集有多个批次可能要遍历取下一批,所有批次的总量才是之前的result。
为了兼容之前的代码做尽量少的改动,把firstBatch取出来放到result里,并且删除firstBatch后结果就与之前的一模一样了。

if (!CollectionUtils.isEmpty(document) && document.containsKey("cursor") && !document.containsKey("result")) {document.put("result",((Document)document.get("cursor")).get("firstBatch"));document.remove("cursor");}
return document;
查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"Mongodb3.4升级高版本mongoTemplate.executeCommand报错The cursor option is required":http://eshow365.cn/6-41513-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!