mongo WriteResult
来源:互联网 发布:40岁程序员干不了 编辑:程序博客网 时间:2024/06/04 18:50
WriteResult 反编译源码
//// Source code recreated from a .class file by IntelliJ IDEA// (powered by Fernflower decompiler)//package com.mongodb;import com.mongodb.MongoException.Network;import java.io.IOException;public class WriteResult { private long _lastCall; private WriteConcern _lastConcern; private CommandResult _lastErrorResult; private final DB _db; private final DBPort _port; private final boolean _lazy; WriteResult(CommandResult o, WriteConcern concern) { this._lastErrorResult = o; this._lastConcern = concern; this._lazy = false; this._port = null; this._db = null; } WriteResult(DB db, DBPort p, WriteConcern concern) { this._db = db; this._port = p; this._lastCall = p.getUsageCount(); this._lastConcern = concern; this._lazy = true; } /** @deprecated */ @Deprecated public CommandResult getCachedLastError() { return this._lastErrorResult; } /** @deprecated */ @Deprecated public WriteConcern getLastConcern() { return this._lastConcern; } /** @deprecated */ @Deprecated public synchronized CommandResult getLastError() { return this.getLastError((WriteConcern)null); } /** @deprecated */ @Deprecated public synchronized CommandResult getLastError(WriteConcern concern) { if(this._lastErrorResult == null || concern != null && (this._lastConcern == null || this._lastConcern.getW() < concern.getW())) { if(this._port != null) { try { this._lastErrorResult = this._port.tryGetLastError(this._db, this._lastCall, concern == null?new WriteConcern():concern); } catch (IOException var3) { throw new Network(var3.getMessage(), var3); } if(this._lastErrorResult == null) { throw new IllegalStateException("The connection may have been used since this write, cannot obtain a result"); } else { this._lastConcern = concern; ++this._lastCall; return this._lastErrorResult; } } else { throw new IllegalStateException("Don't have a port to obtain a write result, and existing one is not good enough."); } } else { return this._lastErrorResult; } } /** @deprecated */ @Deprecated public String getError() { Object foo = this.getField("err"); return foo == null?null:foo.toString(); } public int getN() { return this.getLastError().getInt("n"); } public Object getUpsertedId() { return this.getLastError().get("upserted"); } public boolean isUpdateOfExisting() { return this.getLastError().getBoolean("updatedExisting"); } /** @deprecated */ @Deprecated public Object getField(String name) { return this.getLastError().get(name); } /** @deprecated */ @Deprecated public boolean isLazy() { return this._lazy; } public String toString() { CommandResult res = this.getCachedLastError(); return res != null?res.toString():"N/A"; }}
getN()方法
getLastError.n reports the number of documents updated or removed
只计算updated和removed的记录;
insert的记录不列入其中;
测试
测试方法:db.getLastErrorObj() 获取最后一次操作结果信息
insert 测试:
insert 方法 ,db.getLastErrorObj().n==0
update测试:
update 方法,db.getLastErrorObj().n==3
remove测试:
db.getLastErrorObj().n==1
mongo文档信息
https://docs.mongodb.com/manual/reference/write-concern/
0 0
- mongo WriteResult
- MONGO
- mongo
- mongo
- mongo
- mongo
- mongo
- mongo
- mongo 管理工具 rock mongo
- Mongo登录
- mongo使用
- mongo命令
- mongo笔记
- mongo补充
- mongo索引
- mongo聚合
- mongo 复制
- mongo分片
- 数据库被死锁org.hibernate.exception.LockAcquisitionException: Cannot open connection
- openshift跑app权限报错解决
- ReactNative-JS 调用原生方法实例代码
- 斐波那契数列
- 卖家称千元教共享单车开锁技术 一天可收百辆,一全套的非龙套骗局。
- mongo WriteResult
- MyBatis 关联映射之一对多
- Java面向对象笔记(一)面向对象概述
- RadioButton的图片大小设置
- 【Java学习笔记】08.String和StringBuffer
- easyUI自定义icon
- 动态栈模拟实现
- mybatis中的#和$的区别
- 通过Hook技术对浏览器HTTPS劫持