List of usage examples for com.mongodb WriteResult toString
@Override
public String toString()
From source file:ezbake.data.mongo.EzMongoHandler.java
License:Apache License
@Override public int remove(String collectionName, String jsonQuery, EzSecurityToken security) throws TException, EzMongoBaseException { try {/* w w w. ja v a 2 s .c om*/ HashMap<String, String> auditParamsMap = new HashMap<>(); auditParamsMap.put("action", "remove"); auditParamsMap.put("collectionName", collectionName); auditParamsMap.put("jsonQuery", jsonQuery); auditLog(security, AuditEventType.FileObjectDelete, auditParamsMap); TokenUtils.validateSecurityToken(security, this.getConfigurationProperties()); if (StringUtils.isEmpty(collectionName)) { throw new EzMongoBaseException("collectionName is required."); } final String finalCollectionName = getCollectionName(collectionName); int removedCount = 0; // see if we are able to remove the data in db with user's classification in the user token final List<DBObject> results = mongoFindHelper.findElements(collectionName, jsonQuery, "{ _id: 1}", null, 0, 0, false, security, false, WRITE_OPERATION); if (results.size() > 0) { // construct a list of Objects to use as the filter final List<Object> idList = new ArrayList<Object>(); for (final DBObject result : results) { appLog.info("can remove DBObject (_id): {}", result); idList.add(result.get("_id")); } final DBObject inClause = new BasicDBObject("$in", idList); final DBObject query = new BasicDBObject("_id", inClause); Timer.Context context = getMetricRegistry().getTimers().get(REMOVE_TIMER_NAME).time(); try { final WriteResult writeResult = db.getCollection(finalCollectionName).remove(query); appLog.info("removed - write result: {}", writeResult.toString()); removedCount = writeResult.getN(); } finally { context.stop(); } } else { appLog.info("Did not find any documents to remove with the query {}", jsonQuery); } appLog.info("after remove, removedCount: {}", removedCount); return removedCount; } catch (final Exception e) { throw enrichException("remove", e); } }
From source file:ezbake.data.mongo.helper.MongoUpdateHelper.java
License:Apache License
public int updateContent(String finalCollectionName, DBObject query, DBObject content, boolean upsert, boolean multi) { final WriteResult writeResult = ezMongoHandler.getDb().getCollection(finalCollectionName).update(query, content, upsert, multi);//from w ww . j a v a 2 s .c o m appLog.info("updated - write result: {}", writeResult.toString()); return writeResult.getN(); }
From source file:io.lumeer.storage.mongodb.exception.WriteFailedException.java
License:Open Source License
public WriteFailedException(final WriteResult writeResult) { super(writeResult.toString()); this.writeResult = writeResult; }
From source file:me.schiz.jmeter.protocol.mongodb.sampler.MongoInsertSampler.java
License:Apache License
@Override public SampleResult sample(Entry e) { SampleResult res = new SampleResult(); //String data = getScript(); res.setSampleLabel(getTitle());// w ww .j a v a 2s. c om res.setResponseCodeOK(); res.setSuccessful(true); res.setResponseMessageOK(); res.setSamplerData("db." + getCollection() + ".insert(<json>)"); res.setDataType(SampleResult.TEXT); res.setContentType("text/plain"); // $NON-NLS-1$ res.sampleStart(); try { MongoDB mongoDB = MongoSourceElement.getMongoDB(getSource()); //MongoScriptRunner runner = new MongoScriptRunner(); DB db = mongoDB.getDB(getDatabase(), getUsername(), getPassword()); res.latencyEnd(); BasicDBObject document = (BasicDBObject) JSON.parse(getDocument()); WriteResult wResult = db.getCollection(getCollection()).insert(document); // latencyEnd result = runner.evaluate(db, data); // EvalResultHandler handler = new EvalResultHandler(); // String resultAsString = handler.handle(result); // res.setResponseData(resultAsString.getBytes()); res.setResponseData(wResult.toString().getBytes()); } catch (Exception ex) { res.setResponseCode("500"); // $NON-NLS-1$ res.setSuccessful(false); res.setResponseMessage(ex.toString()); res.setResponseData(ex.getMessage().getBytes()); } finally { res.sampleEnd(); } return res; }
From source file:mongodb.JavaDocAdd.java
public static void addSelfie(DBCollection collection) { BasicDBObject selfie = new BasicDBObject("word", "selfie"); selfie.append("first", "s").append("last", "e"); selfie.append("size", 6).append("category", "New"); BasicDBObject stats = new BasicDBObject("consonants", 3); stats.append("vowels", 3); selfie.append("stats", stats); selfie.append("letters", new String[] { "s", "e", "l", "f", "i" }); BasicDBObject cons = new BasicDBObject("type", "consonants"); cons.append("chars", new String[] { "s", "l", "f" }); BasicDBObject vowels = new BasicDBObject("type", "vowels"); vowels.append("chars", new String[] { "e", "i" }); BasicDBObject[] charsets = new BasicDBObject[] { cons, vowels }; selfie.append("charsets", charsets); WriteResult result = collection.insert(selfie); System.out.println("Insert One Result: \n" + result.toString()); }
From source file:mongodb.JavaDocAdd.java
public static void addGoogleAndTweet(DBCollection collection) { //Create google Object BasicDBObject google = new BasicDBObject("word", "google"); google.append("first", "g").append("last", "e"); google.append("size", 6).append("category", "New"); BasicDBObject stats = new BasicDBObject("consonants", 3); stats.append("vowels", 3); google.append("stats", stats); google.append("letters", new String[] { "g", "o", "l", "e" }); BasicDBObject cons = new BasicDBObject("type", "consonants"); cons.append("chars", new String[] { "g", "l" }); BasicDBObject vowels = new BasicDBObject("type", "vowels"); vowels.append("chars", new String[] { "o", "e" }); BasicDBObject[] charsets = new BasicDBObject[] { cons, vowels }; google.append("charsets", charsets); //Create tweet Object BasicDBObject tweet = new BasicDBObject("word", "tweet"); tweet.append("first", "t").append("last", "t"); tweet.append("size", 6).append("category", "New"); BasicDBObject tstats = new BasicDBObject("consonants", 3); stats.append("vowels", 2); tweet.append("stats", tstats); tweet.append("letters", new String[] { "t", "w", "e" }); BasicDBObject tcons = new BasicDBObject("type", "consonants"); tcons.append("chars", new String[] { "t", "w" }); BasicDBObject tvowels = new BasicDBObject("type", "vowels"); tvowels.append("chars", new String[] { "e" }); BasicDBObject[] tcharsets = new BasicDBObject[] { tcons, tvowels }; tweet.append("charsets", tcharsets); //Insert object array WriteResult result = collection.insert(new BasicDBObject[] { google, tweet }); System.out.println("Insert Multiple Result: \n" + result.toString()); }
From source file:mongodb.JavaDocDelete.java
public static void removeNewDocs(DBCollection collection) { BasicDBObject query = new BasicDBObject("category", "New"); WriteResult result = collection.remove(query); System.out.println("Delete Result: \n" + result.toString()); }
From source file:mongodb.JavaDocSave.java
public static void saveBlueDoc(DBCollection collection) { BasicDBObject query = new BasicDBObject("word", "ocean"); DBObject word = collection.findOne(query); word.put("category", "blue"); WriteResult result = collection.save(word); System.out.println("Update Result: \n" + result.toString()); }
From source file:mongodb.JavaDocSave.java
public static void resetDoc(DBCollection collection) { BasicDBObject query = new BasicDBObject("word", "ocean"); DBObject word = collection.findOne(query); word.put("category", ""); WriteResult result = collection.save(word); System.out.println("Update Result: \n" + result.toString()); }
From source file:mongodb.JavaDocUpdate.java
public static void updateDoc(DBCollection collection) { BasicDBObject query = new BasicDBObject("word", "left"); BasicDBObject update = new BasicDBObject(); update.append("$set", new BasicDBObject("word", "lefty")); BasicDBObject inc = new BasicDBObject("size", 1); inc.append("stats.consonants", 1); update.append("$inc", inc); update.append("$push", new BasicDBObject("letters", "y")); WriteResult result = collection.update(query, update, false, false); System.out.println("Update Result: \n" + result.toString()); }