/** * Removes the file matching the given id. * * @param id the id of the file to be removed * @throws com.mongodb.MongoException if the operation fails */ public void remove(final ObjectId id) { if (id == null) { throw new IllegalArgumentException("file id can not be null"); } filesCollection.remove(new BasicDBObject("_id", id)); chunksCollection.remove(new BasicDBObject("files_id", id)); }
/** * Remove documents from a collection. * * @param query the deletion criteria using query operators. Omit the query parameter or pass an empty document to delete all documents * in the collection. * @return the result of the operation * @throws com.mongodb.WriteConcernException if the write failed due some other failure specific to the delete command * @throws MongoException if the operation failed for some other reason * @mongodb.driver.manual tutorial/remove-documents/ Remove Documents */ public WriteResult remove(final DBObject query) { return remove(query, getWriteConcern()); }
@Override public <T extends Persisted> int destroyAll(Class<T> modelClass) { return collection(modelClass).remove(new BasicDBObject()).getN(); }
protected int destroyAll(String collectionName) { return collection(collectionName).remove(new BasicDBObject()).getN(); }
protected <T extends Persisted> int destroyAll(Class<T> modelClass, DBObject query) { return collection(modelClass).remove(query).getN(); }
protected int destroy(DBObject query, String collectionName) { return collection(collectionName).remove(query).getN(); }
/** * Remove documents from a collection. * * @param query the deletion criteria using query operators. Omit the query parameter or pass an empty document to delete all * documents in the collection. * @param writeConcern {@code WriteConcern} to be used during operation * @return the result of the operation * @throws com.mongodb.WriteConcernException if the write failed due some other failure specific to the delete command * @throws MongoException if the operation failed for some other reason * @mongodb.driver.manual tutorial/remove-documents/ Remove Documents */ public WriteResult remove(final DBObject query, final WriteConcern writeConcern) { return remove(query, new DBCollectionRemoveOptions().writeConcern(writeConcern)); }
@Override public <T extends Persisted> int destroy(T model) { return collection(model).remove(new BasicDBObject("_id", new ObjectId(model.getId()))).getN(); }
/** * Remove documents from a collection. * * @param query the deletion criteria using query operators. Omit the query parameter or pass an empty document to delete all * documents in the collection. * @param writeConcern {@code WriteConcern} to be used during operation * @param encoder {@code DBEncoder} to be used * @return the result of the operation * @throws com.mongodb.WriteConcernException if the write failed due some other failure specific to the delete command * @throws MongoException if the operation failed for some other reason * @mongodb.driver.manual tutorial/remove-documents/ Remove Documents */ public WriteResult remove(final DBObject query, final WriteConcern writeConcern, final DBEncoder encoder) { return remove(query, new DBCollectionRemoveOptions().writeConcern(writeConcern).encoder(encoder)); }
@Override public <T> WriteResult delete(final Query<T> query, final DeleteOptions options) { DBCollection dbColl = query.getCollection(); // TODO remove this after testing. if (dbColl == null) { dbColl = getCollection(query.getEntityClass()); } if (query.getSortObject() != null || query.getOffset() != 0 || query.getLimit() > 0) { throw new QueryException("Delete does not allow sort/offset/limit query options."); } return dbColl.remove(query.getQueryObject(), enforceWriteConcern(options, query.getEntityClass()).getOptions()); }
@Test public void testGet() { getMorphia().map(FacebookUser.class); List<FacebookUser> fbUsers = new ArrayList<FacebookUser>(); fbUsers.add(new FacebookUser(1, "user 1")); fbUsers.add(new FacebookUser(2, "user 2")); fbUsers.add(new FacebookUser(3, "user 3")); fbUsers.add(new FacebookUser(4, "user 4")); getDs().save(fbUsers); assertEquals(4, getDs().getCount(FacebookUser.class)); assertNotNull(getDs().get(FacebookUser.class, 1)); List<FacebookUser> res = toList(getDs().get(FacebookUser.class, asList(1L, 2L)).find()); assertEquals(2, res.size()); assertNotNull(res.get(0)); assertNotNull(res.get(0).id); assertNotNull(res.get(1)); assertNotNull(res.get(1).username); getDs().getCollection(FacebookUser.class).remove(new BasicDBObject()); getAds().insert(fbUsers); assertEquals(4, getDs().getCount(FacebookUser.class)); assertNotNull(getDs().get(FacebookUser.class, 1)); res = toList(getDs().get(FacebookUser.class, asList(1L, 2L)).find()); assertEquals(2, res.size()); assertNotNull(res.get(0)); assertNotNull(res.get(0).id); assertNotNull(res.get(1)); assertNotNull(res.get(1).username); }
@Override public void deleteSchema(Name name) throws IOException { if (name == null) { return; } String typeName = name.getLocalPart(); if (typeName == null) { return; } collection.remove(new BasicDBObject(FeatureTypeDBObject.KEY_typeName, typeName)); }
@Test public void testGet() { final String ns = "hotels"; final Rectangle rect = new Rectangle(10, 10); getDb().getCollection(ns).remove(new BasicDBObject()); getAds().save(ns, rect); assertEquals(1, getAds().find(ns, Rectangle.class).count()); final Rectangle rectLoaded = getAds().find(ns, Rectangle.class) .filter("_id", rect.getId()) .first(); assertEquals(rect.getId(), rectLoaded.getId()); assertEquals(rect.getArea(), rectLoaded.getArea(), 0); } }
@Test public void testDeleteDoesNotDeleteAnythingWhenGivenAnIncorrectId() { // given final String ns = "someCollectionName"; getDb().getCollection(ns).remove(new BasicDBObject()); final Rectangle rect = new Rectangle(10, 10); ObjectId id = new ObjectId(); rect.setId(id); getAds().save(ns, rect); assertEquals(1, getAds().find(ns, Rectangle.class).count()); // when giving an ID that is not the entity ID. Note that at the time of writing this will also log a validation warning getAds().delete(getAds().find(ns, Rectangle.class).filter("_id", 1)); // then assertEquals(1, getDb().getCollection(ns).count()); }
@Test public void testDeleteWithAnEntityTypeAndId() { // given final String ns = "someCollectionName"; getDb().getCollection(ns).remove(new BasicDBObject()); final Rectangle rect = new Rectangle(10, 10); ObjectId id = new ObjectId(); rect.setId(id); getAds().save(ns, rect); assertEquals(1, getAds().find(ns, Rectangle.class).count()); // when getAds().delete(getAds().find(ns, Rectangle.class).filter("_id", id)); // then assertEquals(0, getAds().find(ns, Rectangle.class).count()); }
public void deleteByColumn(String schemaName, String tableName, String columnName, Object columnValue) { DBCollection dbCollection = mongoDb.getCollection(tableName); BasicDBObject query = new BasicDBObject(); query.put(columnName, columnValue); KunderaCoreUtils.printQuery("Delete column:" + query, showQuery); dbCollection.remove(query, getWriteConcern(), encoder); }
@Test public void testDeleteWillRemoveAnyDocumentWithAMatchingId() { // given final String ns = "someCollectionName"; getDb().getCollection(ns).remove(new BasicDBObject()); final Rectangle rect = new Rectangle(10, 10); ObjectId rectangleId = new ObjectId(); rect.setId(rectangleId); getAds().save(ns, rect); final Circle circle = new Circle(); circle.setId(new ObjectId()); getAds().save(ns, circle); assertEquals(2, getAds().find(ns, Rectangle.class).count()); // when getAds().delete(getAds().find(ns, Circle.class).filter("_id", rectangleId)); // then assertEquals(1, getAds().find(ns, Circle.class).count()); }
rect.setId(id); getDb().getCollection(ns).remove(new BasicDBObject());
dbCollection.remove(query, getWriteConcern(), encoder);