Package com.mongodb

Examples of com.mongodb.DBCollection.findOne()


  public void testCollectionViaFindOne() throws UnknownHostException, MongoException {
    MongoDao dao = MongoDao.Factory.newTestMongoDao();
   
    DBCollection col = dao.getDbCollection();
   
    DBObject myDoc = col.findOne();
    logger.info("first object: "+myDoc);
    logger.info("counted objects: "+col.getCount());

  }
 
View Full Code Here


    }
    JsonObject matcher = message.body.getObject("matcher");
    DBCollection coll = db.getCollection(collection);
    DBObject res;
    if (matcher == null) {
      res = coll.findOne();
    } else {
      res = coll.findOne(jsonToDBObject(matcher));
    }
    JsonObject reply = new JsonObject();
    if (res != null) {
View Full Code Here

    DBCollection coll = db.getCollection(collection);
    DBObject res;
    if (matcher == null) {
      res = coll.findOne();
    } else {
      res = coll.findOne(jsonToDBObject(matcher));
    }
    JsonObject reply = new JsonObject();
    if (res != null) {
      String s = res.toString();
      JsonObject m = new JsonObject(s);
View Full Code Here

    @CheckForNull
    <T extends Document> T findUncached(Collection<T> collection, String key) {
        DBCollection dbCollection = getDBCollection(collection);
        long start = start();
        try {
            DBObject obj = dbCollection.findOne(getByKeyQuery(key).get());
            if (obj == null) {
                return null;
            }
            T doc = convertFromDBObject(collection, obj);
            if (doc != null) {
View Full Code Here

    if (db != null && db.collectionExists(tableName.getColumnFamily())) {
      dbCollection = db.getCollection(tableName.getColumnFamily());
    } else
      return;

    DBObject row = dbCollection.findOne(rowKey);
    if(row == null) {
      return;
    }
    else {
      Set<String> fieldSet = row.keySet();
View Full Code Here

       
        assertEquals("Response isn't of type WriteResult", WriteResult.class, result.getClass());
       
        DBCollection dynamicCollection = mongo.getDB("otherDB").getCollection(testCollection.getName());
       
        DBObject b = dynamicCollection.findOne("testInsertDynamicityEnabledDBOnly");
        assertNotNull("No record with 'testInsertDynamicityEnabledDBOnly' _id", b);
       
        b = testCollection.findOne("testInsertDynamicityEnabledDBOnly");
        assertNull("There is a record with 'testInsertDynamicityEnabledDBOnly' _id in the test collection", b);
       
View Full Code Here

       
        assertEquals("Response isn't of type WriteResult", WriteResult.class, result.getClass());
       
        DBCollection dynamicCollection = db.getCollection("otherCollection");
       
        DBObject b = dynamicCollection.findOne("testInsertDynamicityEnabledCollectionOnly");
        assertNotNull("No record with 'testInsertDynamicityEnabledCollectionOnly' _id", b);
       
        b = testCollection.findOne("testInsertDynamicityEnabledDBOnly");
        assertNull("There is a record with 'testInsertDynamicityEnabledCollectionOnly' _id in the test collection", b);
       
View Full Code Here

       
        assertEquals("Response isn't of type WriteResult", WriteResult.class, result.getClass());
       
        DBCollection dynamicCollection = mongo.getDB("otherDB").getCollection("otherCollection");
       
        DBObject b = dynamicCollection.findOne("testInsertDynamicityEnabledDBAndCollection");
        assertNotNull("No record with 'testInsertDynamicityEnabledDBAndCollection' _id", b);
       
        b = testCollection.findOne("testInsertDynamicityEnabledDBOnly");
        assertNull("There is a record with 'testInsertDynamicityEnabledDBAndCollection' _id in the test collection", b);
       
View Full Code Here

        mock.reset();
        // ensure that the persisted lastVal is startTimestamp + 300min
        Calendar cal300 = (Calendar) startTimestamp.clone();
        cal300.add(Calendar.MINUTE, 300);
        context.stopRoute("tailableCursorConsumer2");
        assertEquals(cal300.getTime(), trackingCol.findOne(new BasicDBObject("persistentId", "darwin")).get(MongoDbTailTrackingConfig.DEFAULT_FIELD));
        context.startRoute("tailableCursorConsumer2");
       
        // expect 300 messages and not 600
        mock.expectedMessageCount(300);
        // pump 300 records
View Full Code Here

        assertEquals(cal301.getTime(), ((DBObject) firstBody).get("increasing"));
        // check that the persisted lastVal after stopping the route is startTimestamp + 600min
        context.stopRoute("tailableCursorConsumer2");
        Calendar cal600 = (Calendar) startTimestamp.clone();
        cal600.add(Calendar.MINUTE, 600);
        assertEquals(cal600.getTime(), trackingCol.findOne(new BasicDBObject("persistentId", "darwin")).get(MongoDbTailTrackingConfig.DEFAULT_FIELD));
    }
   
    @Test
    public void testCustomTailTrackLocation() throws Exception {
        assertEquals(0, cappedTestCollection.count());
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.