use of com.mongodb.DBCollection in project morphia by mongodb.
the class TestQuery method testCommentsShowUpInLogs.
@Test
public void testCommentsShowUpInLogs() {
getDs().save(asList(new Pic("pic1"), new Pic("pic2"), new Pic("pic3"), new Pic("pic4")));
getDb().command(new BasicDBObject("profile", 2));
String expectedComment = "test comment";
getDs().find(Pic.class).asList(new FindOptions().modifier("$comment", expectedComment));
DBCollection profileCollection = getDb().getCollection("system.profile");
assertNotEquals(0, profileCollection.count());
DBObject profileRecord = profileCollection.findOne(new BasicDBObject("op", "query").append("ns", getDs().getCollection(Pic.class).getFullName()));
final Object commentPre32 = ((DBObject) profileRecord.get("query")).get("$comment");
final Object commentPost32 = ((DBObject) profileRecord.get("query")).get("comment");
assertTrue(profileRecord.toString(), expectedComment.equals(commentPre32) || expectedComment.equals(commentPost32));
turnOffProfilingAndDropProfileCollection();
}
use of com.mongodb.DBCollection in project mongomvcc by igd-geo.
the class MongoDBVDatabaseBenchmark method plainOldInsertDelete.
/**
* Inserts a lot of documents using plain old MongoDB and then deletes them
*/
@Test
@BenchmarkOptions(benchmarkRounds = 2, warmupRounds = 1)
public void plainOldInsertDelete() {
plainOldInsert();
DBCollection coll = _db.getCollection("persons");
for (long i = 0; i < DOCUMENTS; ++i) {
coll.remove(new BasicDBObject("_id", 1 + i));
}
}
use of com.mongodb.DBCollection in project mongomvcc by igd-geo.
the class MongoDBVDatabaseBenchmark method plainOldInsertDeleteInsertQuery.
/**
* Queries a lot of objects after inserting, deleting and inserting again
*/
@Test
@BenchmarkOptions(benchmarkRounds = 2, warmupRounds = 1)
public void plainOldInsertDeleteInsertQuery() {
plainOldInsertDeleteInsert();
_master.commit();
DBCollection coll = _db.getCollection("persons");
for (DBObject o : coll.find()) {
assertTrue(((Long) o.get("age")).longValue() >= DOCUMENTS);
}
}
use of com.mongodb.DBCollection in project mongomvcc by igd-geo.
the class MongoDBVMaintenance method doFindDanglingCommits.
private long[] doFindDanglingCommits(long expiry, TimeUnit unit) {
long maxTime = getMaxTime(expiry, unit);
//load all commits which are older than the expiry time. mark them as dangling
DBCollection collCommits = _db.getDB().getCollection(MongoDBConstants.COLLECTION_COMMITS);
DBCursor commits = collCommits.find(new BasicDBObject(MongoDBConstants.TIMESTAMP, //also include commits without a timestamp
new BasicDBObject("$not", new BasicDBObject("$gte", maxTime))), new BasicDBObject(MongoDBConstants.ID, 1));
IdSet danglingCommits = new IdHashSet();
for (DBObject o : commits) {
long cid = (Long) o.get(MongoDBConstants.ID);
danglingCommits.add(cid);
}
//walk through all branches and eliminate commits which are not dangling
DBCollection collBranches = _db.getDB().getCollection(MongoDBConstants.COLLECTION_BRANCHES);
DBCursor branches = collBranches.find(new BasicDBObject(), new BasicDBObject(MongoDBConstants.CID, 1));
VHistory history = _db.getHistory();
IdSet alreadyCheckedCommits = new IdHashSet();
for (DBObject o : branches) {
long cid = (Long) o.get(MongoDBConstants.CID);
while (cid != 0) {
if (alreadyCheckedCommits.contains(cid)) {
break;
}
alreadyCheckedCommits.add(cid);
danglingCommits.remove(cid);
cid = history.getParent(cid);
}
}
//all remaining commits must be dangling
return danglingCommits.toArray();
}
use of com.mongodb.DBCollection in project mongomvcc by igd-geo.
the class MongoDBVMaintenance method pruneUnreferencedDocuments.
@Override
public long pruneUnreferencedDocuments(String collection, long expiry, TimeUnit unit) {
long[] oids = findUnreferencedDocuments(collection, expiry, unit);
DBCollection coll = _db.getDB().getCollection(collection);
//delete documents in chunks, so we avoid sending an array that is
//larger than the maximum document size
final int sliceCount = 1000;
for (int i = 0; i < oids.length; i += sliceCount) {
int maxSliceCount = Math.min(sliceCount, oids.length - i);
long[] slice = new long[maxSliceCount];
System.arraycopy(oids, i, slice, 0, maxSliceCount);
coll.remove(new BasicDBObject(MongoDBConstants.ID, new BasicDBObject("$in", slice)));
}
return oids.length;
}
Aggregations