Package com.mongodb

Examples of com.mongodb.CommandResult


        if (wc.callGetLastError()) {
            assertNotNull(wr.getCachedLastError());
        } else {
            assertNull(wr.getCachedLastError());
        }
        CommandResult cr = wr.getLastError();
        assertTrue(cr.ok());
    }
View Full Code Here


        Object result = template.requestBodyAndHeader("direct:noWriteConcern", "{\"scientist\":\"newton\"}", MongoDbConstants.WRITECONCERN, WriteConcern.SAFE);
        assertTrue("Result is not of type WriteResult", result instanceof WriteResult);
        WriteResult wr = (WriteResult) result;
        // should not be null because with WriteConcern.SAFE, getLastError was called implicitly by the driver
        assertNotNull(wr.getCachedLastError());
        CommandResult cr = wr.getLastError();
        assertTrue(cr.ok());
       
        // same behaviour should be reproduced with String 'SAFE'
        result = template.requestBodyAndHeader("direct:noWriteConcern", "{\"scientist\":\"newton\"}", MongoDbConstants.WRITECONCERN, "SAFE");
        assertTrue("Result is not of type WriteResult", result instanceof WriteResult);
        wr = (WriteResult) result;
        // should not be null because with WriteConcern.SAFE, getLastError was called implicitly by the driver
        assertNotNull(wr.getCachedLastError());
        cr = wr.getLastError();
        assertTrue(cr.ok());
    }
View Full Code Here

    public void testCappedCollection()
    {
        // Validate schema
        DBCollection collection = db.getCollection("MongoDBCappedEntity");
        Assert.assertTrue(collection.isCapped());
        CommandResult stats = collection.getStats();

        Object maxObj = stats.get(MongoDBConstants.MAX);
        Assert.assertNotNull(maxObj);
        int max = Integer.parseInt(maxObj.toString());
        Assert.assertEquals(10, max);

        /*
 
View Full Code Here

   
    private void processAndTransferWriteResult(WriteResult result, Exchange exchange) {
        // if invokeGetLastError is set, or a WriteConcern is set which implicitly calls getLastError, then we have the chance to populate
        // the MONGODB_LAST_ERROR header, as well as setting an exception on the Exchange if one occurred at the MongoDB server
        if (endpoint.isInvokeGetLastError() || (endpoint.getWriteConcern() != null ? endpoint.getWriteConcern().callGetLastError() : false)) {
            CommandResult cr = result.getCachedLastError() == null ? result.getLastError() : result.getCachedLastError();
            exchange.getOut().setHeader(MongoDbConstants.LAST_ERROR, cr);
            if (!cr.ok()) {
                exchange.setException(MongoDbComponent.wrapInCamelMongoDbException(cr.getException()));
            }
        }

        // determine where to set the WriteResult: as the OUT body or as an IN
        // message header
View Full Code Here

    }

    public List findData() {

        logger.debug("find stats  by {}", query);
        CommandResult result = null;//mongoDb.runCmd(query);
        logger.debug("stats mongo result {}", result);
        Object data = result.get("retval");

        return (List) data;
    }
View Full Code Here

            @Override
            public CommandResult call() throws Exception {

                logger.debug("run mongo script = {}", script);
                CommandResult result = project.fetchMongoTemplate().getDb().doEval(script, new BasicDBObject().append("nolock", true));
                logger.debug("mongo task response {}", result);
                return result;
            }
        });
        executor.submit(_fuFutureTask);
View Full Code Here

    // when
    collection.insert( createDocument("{_id:0, fullName: \"User 1\"}") );
   
    // then: except duplicate key error
    CommandResult cr = db.getLastError();
    assertThat( cr.getInt("code"), is(11000) );
  }
View Full Code Here

    // when
    collection.insert( createDocument("{_id:101, fullName: \"User 100\"}") );
   
    // then: except duplicate key error
    CommandResult cr = db.getLastError();
    assertThat( cr.getInt("code"), is(11000) );
  }
View Full Code Here

    // remove(collection);
    // bsonize();
  }
 
  private static void getLastError(DB db) {
    CommandResult cr;
   
    cr = db.getLastError(WriteConcern.NORMAL);
    System.out.println(cr);
  }
View Full Code Here

        }
    }

    private void initMongoInstances(ExecutableType type) throws Exception {
        logger.debug("*** initMongoInstances(" + type + ") ***");
        CommandResult cr;
        Settings rsSettings = settings.getByPrefix(type.configKey + '.');
        int[] ports;
        if (rsSettings.getAsBoolean("useDynamicPorts", false)) {
            ports = new int[] { Network.getFreeServerPort(), Network.getFreeServerPort(), Network.getFreeServerPort() };
        } else {
View Full Code Here

TOP

Related Classes of com.mongodb.CommandResult

Copyright © 2018 www.massapicom. 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.