List of usage examples for com.mongodb DBCollection remove
public WriteResult remove(final DBObject query)
From source file:com.streamreduce.core.dao.GenericCollectionDAO.java
License:Apache License
public BasicDBObject removeCollectionEntry(SobaObject sobaObject, ObjectId id) { DB db = getDatabase(DAODatasourceType.BUSINESS); String collectionName = getCollectionNameFromType(sobaObject); DBCollection collection = db.getCollection(collectionName); BasicDBObject payload = getById(DAODatasourceType.BUSINESS, collectionName, id); if (payload != null) { collection.remove(payload); }//from w w w. j a v a2s. c o m return payload; }
From source file:com.streamreduce.core.dao.GenericCollectionDAO.java
License:Apache License
public BasicDBObject removeCollectionEntry(DAODatasourceType datasourceType, String collectionName, ObjectId id) {//from w w w. j a va 2 s.c o m DB db = getDatabase(datasourceType); DBCollection collection = db.getCollection(collectionName); BasicDBObject payload = getById(datasourceType, collectionName, id); if (payload != null) { collection.remove(payload); } return payload; }
From source file:com.streamreduce.core.service.UserServiceImpl.java
License:Apache License
/** * SOBA-1617 -- bootstrap the Metric collections with proper indexes * * @param account - a valid account//from w ww. j a va2 s . c om */ private void createMetricInbox(Account account) { // create a bogus object DB db = genericCollectionDAO.getDatabase(DAODatasourceType.MESSAGE); DBCollection collection = db.getCollection(MessageUtils.getMetricInboxPath(account)); BasicDBObject dummyObj = new BasicDBObject(); collection.insert(dummyObj); // add indexes collection.ensureIndex("metricGranularity"); collection.ensureIndex("metricName"); // remove bogus object collection.remove(dummyObj); }
From source file:com.sube.daos.mongodb.CardMongoDaoImpl.java
License:Apache License
@Override public void removeAll() { DBCollection collection = getCardCollection(); collection.remove(new BasicDBObject()); }
From source file:com.sube.daos.mongodb.CardUsagesMongoDaoImpl.java
License:Apache License
@Override public void removeAll() { DBCollection collection = getCardUsagesCollection(); collection.remove(new BasicDBObject()); }
From source file:com.sube.daos.mongodb.EntryDaoImpl.java
License:Apache License
@Override public void removeAll() { DBCollection collection = getCollection(); collection.remove(new BasicDBObject()); }
From source file:com.sube.daos.mongodb.GenericProviderDaoImpl.java
License:Apache License
@Override public void removeAll() { DBCollection collection = getProvidersCollection(); collection.remove(new BasicDBObject()); }
From source file:com.tengen.Final7.java
License:Apache License
public static void main(String[] args) throws IOException { MongoClient client = new MongoClient(); DB db = client.getDB("photoshare"); int i = 0;//www . j a v a 2 s . co m DBCollection album = db.getCollection("albums"); DBCollection image = db.getCollection("images"); DBCursor cur = image.find(); cur.next(); while (cur.hasNext()) { Object id = cur.curr().get("_id"); DBCursor curalbum = album.find(new BasicDBObject("images", id)); if (!curalbum.hasNext()) { image.remove(new BasicDBObject("_id", id)); } cur.next(); } }
From source file:com.terkaly.JavaMongoDB.App.java
License:Open Source License
public static void main(String[] args) { try {/*w w w . ja v a 2s. co m*/ // Create a connection using mongoClient // 23.99.88.154 is obtained from the portal MongoClient mongoClient = new MongoClient("[ put your ip address here ]", 27017); // Get a connection to mydb DB db = mongoClient.getDB("mydb"); // mydb has one or more collections, get "testCollection" DBCollection collection = db.getCollection("testCollection"); // Create an empty object BasicDBObject empty = new BasicDBObject(); // Clear out testCollection collection.remove(empty); // Acknowledges the write operation only // after committing the data to the journal mongoClient.setWriteConcern(WriteConcern.JOURNALED); // Here is the data format in JSON // { // "name": "MongoDB", // "type": "database", // "count": 1, // "info": { // "x": 203, // "y": 102 // } // } BasicDBObject doc = new BasicDBObject("name", "MongoDB").append("type", "database").append("count", 1) .append("info", new BasicDBObject("x", 203).append("y", 102)); collection.insert(doc); DBObject myDoc = collection.findOne(); System.out.println(myDoc); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.tomtom.speedtools.mongodb.DaoUtils.java
License:Apache License
/** * Removes the given object from the given collection. The entity must fully match the database record to be * removed.//w w w. jav a2s . c o m * * @param <T> The type of the object to remove. * @param collection Collection from which to remove the object. * @param mapper Mapper to be used to transform the object. * @param entity The object to be removed. * @throws EntityRemoveException Thrown if the object cannot be removed. The error will have been logged. */ public static <T> void removeEntity(@Nonnull final DBCollection collection, @Nonnull final EntityMapper<T> mapper, @Nonnull final T entity) throws EntityRemoveException { assert collection != null; assert mapper != null; assert entity != null; try { final DBObject dbObject = mapper.toDb(entity); collection.remove(dbObject); } catch (final MapperException | MongoException e) { final String message = "Map entity failed: type=" + entity.getClass().getSimpleName() + ", collection=" + collection.getName() + '.'; LOG.error("removeEntity: " + message, e); throw new EntityRemoveException(message, e); } }