Instructions for using updateapi interface of MongoDB database

From two aspects to explain. Shell command line description, java client API description; java client example: set = conn.prepareStatement(querysql+fromsql).executeQuery() ; while(set. next()){ DBObject q = new BasicDBObject().append(“T”, “a”) .append(“CI”, String. valueOf(set. getInt(1))) .append(“AI”, String.valueOf(set.getInt(3))); DBObject o = new BasicDBObject().append(“$set”, new BasicDBObject().append(“CN”, set.getString(2)) .append(“AN”, set.getString(4)).append(“S”, set. getString(5))); Mongodb.getDB(“yqflog”).getCollection(“info”).update(q, o, true , true ); } mongodb java client api: /** * calls {@link DBCollection#update(com.mongodb.DBObject, com.mongodb.DBObject, boolean, boolean, com.mongodb.WriteConcern)} with default Write Concern. * @param q search query for old object to update * @param o object with which to update q * @param upsert if the database should create the element if it does not exist * @param multi if the update should be applied to all objects matching (db version 1.1.3 and above) * * * See http://www.mongodb.org/display/DOCS/Atomic+Operations * @return * @throws MongoException * @dochub update */ public WriteResult update( DBObject q , DBObject o , boolean upsert , boolean multi )   throws MongoException { return update( q , o , upsert , multi , getWriteConcern() ); } shell command line: db.collection.update( criteria, objNew, upsert, multi ) Arguments: criteria – query which selects the record to update; objNew – updated object or $ operators (e.g., $inc) which manipulate the object…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: [email protected]

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索