完整异常信息
{ “ok” : 0, “code” : 16, “errmsg” : “no write ops were included in the batch” }
直译为:在批处理中不包括写操作
抛出该异常的原因是:
在执行写操作时,写入的数据为 null 或者 size 为 0
如:
// 初始化 DB 实例
DB db = .....
List<DBObject> documents = new ArrayList<DBObject>();
db.getCollection(colName).insert(documents);
执行以上语句会抛出:
no write ops were included in the batch
因为 list 集合的长度为 0,mongodb 中不支持写入 list 长度为 0 的数据