List of usage examples for com.mongodb WriteResult getN
public int getN()
From source file:io.lumeer.storage.mongodb.dao.project.MorphiaDocumentDao.java
License:Open Source License
@Override public void deleteDocument(final String id) { WriteResult writeResult = datastore.delete(databaseCollection(), MorphiaDocument.class, new ObjectId(id)); if (writeResult.getN() != 1) { throw new WriteFailedException(writeResult); }//from www .j a v a2 s. c o m }
From source file:io.lumeer.storage.mongodb.dao.project.MorphiaViewDao.java
License:Open Source License
public void deleteView(final String id) { WriteResult writeResult = datastore.delete(databaseCollection(), MorphiaView.class, new ObjectId(id)); if (writeResult.getN() != 1) { throw new WriteFailedException(writeResult); }//from ww w. j av a 2 s . c om }
From source file:io.lumeer.storage.mongodb.dao.system.MorphiaOrganizationDao.java
License:Open Source License
@Override public void deleteOrganization(final String organizationId) { WriteResult writeResult = datastore.delete(MorphiaOrganization.class, new ObjectId(organizationId)); if (writeResult.getN() != 1) { throw new WriteFailedException(writeResult); }//from ww w.j a va2 s.c om }
From source file:me.carbou.mathieu.tictactoe.db.DBCollection.java
License:Apache License
public int update(Map<String, Object> where, Map<String, Object> update, boolean upsert, boolean multi) { WriteResult writeResult = getCollection().update(new BasicDBObject(addWhere(where)), new BasicDBObject(preUpdate(update)), upsert, multi); return writeResult.getN(); }
From source file:mongoDB.MongoDbClientAllImagesAsByteArrays.java
License:Open Source License
@Override public int acceptFriend(int invitorID, int inviteeID) { // delete from pending of the invitee // add to confirmed of both invitee and invitor int retVal = 0; if (invitorID < 0 || inviteeID < 0) return -1; com.mongodb.DB db = null;/*from w w w .j av a 2s .c o m*/ try { db = mongo.getDB(database); db.requestStart(); DBCollection collection = db.getCollection("users"); DBObject q = new BasicDBObject().append("_id", inviteeID); // pull out of invitees pending BasicDBObject updateCommand = new BasicDBObject(); updateCommand.put("$pull", new BasicDBObject("PendFriends", invitorID)); WriteResult res = collection.update(q, updateCommand, false, false, writeConcern); // add to invitees confirmed updateCommand = new BasicDBObject(); updateCommand.put("$push", new BasicDBObject("ConfFriends", invitorID)); res = collection.update(q, updateCommand, false, false, writeConcern); // add to invitore confirmed q = new BasicDBObject().append("_id", invitorID); updateCommand = new BasicDBObject(); updateCommand.put("$push", new BasicDBObject("ConfFriends", inviteeID)); res = collection.update(q, updateCommand, false, false, writeConcern); db.requestDone(); return res.getN() == 1 ? 0 : -1; } catch (Exception e) { System.out.println(e.toString()); retVal = -1; } finally { if (db != null) { db.requestDone(); } } return retVal; }
From source file:mongoDB.MongoDbClientAllImagesAsByteArrays.java
License:Open Source License
@Override public int rejectFriend(int invitorID, int inviteeID) { // remove from pending of invitee int retVal = 0; if (invitorID < 0 || inviteeID < 0) return -1; com.mongodb.DB db = null;/* w w w . ja v a2 s. c o m*/ try { db = mongo.getDB(database); db.requestStart(); DBCollection collection = db.getCollection("users"); DBObject q = new BasicDBObject().append("_id", inviteeID); // pull out of invitees pending BasicDBObject updateCommand = new BasicDBObject(); updateCommand.put("$pull", new BasicDBObject("PendFriends", invitorID)); WriteResult res = collection.update(q, updateCommand, false, false, writeConcern); db.requestDone(); return res.getN() == 1 ? 0 : -1; } catch (Exception e) { System.out.println(e.toString()); retVal = -1; } finally { if (db != null) { db.requestDone(); } } return retVal; }
From source file:mongoDB.MongoDbClientAllImagesAsByteArrays.java
License:Open Source License
@Override public int delCommentOnResource(int resourceCreatorID, int resourceID, int manipulationID) { int retVal = 0; if (resourceCreatorID < 0 || resourceID < 0 || manipulationID < 0) return -1; com.mongodb.DB db = null;//from w w w. j a va 2 s . co m try { // get the appropriate database db = mongo.getDB(database); db.requestStart(); if (!manipulationArray) { // consider a separate manipoulations // table DBCollection collection = db.getCollection("manipulation"); DBObject q = new BasicDBObject().append("mid", Integer.toString(manipulationID)).append("rid", Integer.toString(resourceID)); collection.remove(q); } else { DBCollection collection = db.getCollection("resources"); DBObject q = new BasicDBObject().append("_id", resourceID); BasicDBObject updateCommand = new BasicDBObject("Manipulations", new BasicDBObject("mid", Integer.toString(manipulationID))); WriteResult res = collection.update(q, new BasicDBObject("$pull", updateCommand), false, false, writeConcern); if (res.getN() != 1) return -1; } } catch (Exception e) { System.out.println(e.toString()); retVal = -1; } finally { if (db != null) { db.requestDone(); } } return retVal; }
From source file:mongoDB.MongoDbClientAllImagesAsByteArrays.java
License:Open Source License
@Override public int thawFriendship(int friendid1, int friendid2) { // delete from both their confFriends int retVal = 0; if (friendid1 < 0 || friendid2 < 0) return -1; com.mongodb.DB db = null;// w w w. j a v a2 s . c o m try { db = mongo.getDB(database); db.requestStart(); DBCollection collection = db.getCollection("users"); DBObject q = new BasicDBObject().append("_id", friendid1); // pull out of friend1 BasicDBObject updateCommand = new BasicDBObject(); updateCommand.put("$pull", new BasicDBObject("ConfFriends", friendid2)); WriteResult res = collection.update(q, updateCommand, false, false, writeConcern); if (res.getN() != 1) return -1; q = new BasicDBObject().append("_id", friendid2); // pull out of friendid2 updateCommand = new BasicDBObject(); updateCommand.put("$pull", new BasicDBObject("ConfFriends", friendid1)); res = collection.update(q, updateCommand, false, false, writeConcern); db.requestDone(); return res.getN() == 1 ? 0 : -1; } catch (Exception e) { System.out.println(e.toString()); retVal = -1; } finally { if (db != null) { db.requestDone(); } } return retVal; }
From source file:mypackage.CreateDB.java
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); try (PrintWriter out = response.getWriter()) { String getDBName = request.getParameter("dbname"); MongoClient mongoClient = new MongoClient("localhost", 27017); HttpSession httpSession = request.getSession(false); DB db = mongoClient.getDB("mydb"); DBCollection dBCollection = db.getCollection(httpSession.getAttribute("uname") + "DB"); BasicDBObject dBObject = new BasicDBObject(); dBObject.put("kapil", getDBName); WriteResult writeResult = dBCollection.insert(dBObject); if (writeResult.getN() == 0) { out.print("true"); MongoDatabase mongoDatabase = mongoClient.getDatabase(getDBName); mongoDatabase.createCollection("Welcome"); mongoDatabase.drop();// w ww . ja v a 2 s. c om } else { out.print("false"); } } }
From source file:net.handle.server.MongoDBHandleStorage.java
License:Open Source License
/** * ****************************************************************** * Delete the specified handle in the database. * ******************************************************************* *//*from w ww. j a v a2 s . co m*/ public boolean deleteHandle(byte handle[]) throws HandleException { if (readOnly) throw new HandleException(HandleException.STORAGE_RDONLY, "Server is read-only"); final String handleStr = Util.decodeString(handle); final BasicDBObject query = new BasicDBObject("handle", handleStr); final DBCollection collection = getCollection(handle); final WriteResult result = collection.remove(query); return (result.getN() != 0); }