/** * Closes the underlying cursor. */ public void close() { if (wrapped != null && wrapped instanceof DBCursor) { ((DBCursor) wrapped).close(); } }
protected List<DBObject> cursorToList(DBCursor cursor) { if (cursor == null) { return Collections.emptyList(); } try { return Lists.newArrayList((Iterable<DBObject>) cursor); } finally { cursor.close(); } }
/** * Finds a list of files matching the given query. * * @param query the filter to apply * @param sort the fields to sort with * @return list of gridfs files * @throws com.mongodb.MongoException if the operation fails */ public List<GridFSDBFile> find(final DBObject query, final DBObject sort) { List<GridFSDBFile> files = new ArrayList<GridFSDBFile>(); DBCursor cursor = filesCollection.find(query); if (sort != null) { cursor.sort(sort); } try { while (cursor.hasNext()) { files.add(injectGridFSInstance(cursor.next())); } } finally { cursor.close(); } return Collections.unmodifiableList(files); }
/** * Returns the first document that matches the query. * * @return the first matching document * @since 2.12 */ @Nullable public DBObject one() { DBCursor findOneCursor = copy().limit(-1); try { return findOneCursor.hasNext() ? findOneCursor.next() : null; } finally { findOneCursor.close(); } }
if (cursor != null) { logger.trace("Closing oplog cursor"); cursor.close();
fileListCursor.close();
@Override public void close() throws IOException { cursor.close(); } }
if (cursor != null) { logger.trace("Closing initial import cursor"); cursor.close();
cursor.close();
@Test public void testOutNamedCollection() { checkMinServerVersion(2.6); getDs().save(asList(new Book("The Banquet", "Dante", 2, "Italian", "Sophomore Slump"), new Book("Divine Comedy", "Dante", 1, "Not Very Funny", "I mean for a 'comedy'", "Ironic"), new Book("Eclogues", "Dante", 2, "Italian", ""), new Book("The Odyssey", "Homer", 10, "Classic", "Mythology", "Sequel"), new Book("Iliad", "Homer", 10, "Mythology", "Trojan War", "No Sequel"))); getDs().createAggregation(Book.class) .match(getDs().getQueryFactory().createQuery(getDs()) .field("author").equal("Homer")) .group("author", grouping("copies", sum("copies"))) .out("testAverage", Author.class); DBCursor testAverage = getDb().getCollection("testAverage").find(); Assert.assertNotNull(testAverage); try { Assert.assertEquals(20, testAverage.next().get("copies")); } finally { testAverage.close(); } }
@Override public void close() throws QueryEvaluationException { cursor.close(); } };
public void close() { if (wrapped != null && wrapped instanceof DBCursor) { ((DBCursor) wrapped).close(); } } }
@Override public void close() { try{ cursor.close(); } catch (Exception e) {} } @Override
/** * kills the current cursor on the server. */ public void close() { cursor.close(); }
@Override public boolean hasNext() { boolean next = cursor.hasNext(); if (!next) { cursor.close(); } return next; }
protected <T extends MongoIdentifiableEntity> List<T> convertCursor(Class<T> type, DBCursor cursor, MongoStoreInvocationContext context) { List<T> result = new ArrayList<T>(); try { for (DBObject dbObject : cursor) { T entity = convertDBObjectToEntity(type, dbObject, context); result.add(entity); } } finally { cursor.close(); } return result; }
BasicDBObject gtquery = new BasicDBObject("number", new BasicDBObject("$gt", 3).append("$lt", 5) ); DBCursor cur = col.find(gtquery); try { while (cur.hasNext()) { System.out.println(cur.next()); } } finally { cur.close(); }
DBCursor cursor = coll.find(); try { while(cursor.hasNext()) { coll2.insert(cursor.next()); } } finally { cursor.close(); }
MongoClient mongoClient = new MongoClient(); DB db = mongoClient.getDB("test"); DBCollection coll = db.getCollection("testCollection"); BasicDBObject query = new BasicDBObject("_id", "51a29f6413dc992c24e0283e"); DBCursor cursor = coll.find(query); try { while(cursor.hasNext()) { System.out.println(cursor.next()); } } finally { cursor.close(); }