use of com.mongodb.BasicDBObject in project camel by apache.
the class MongoDbDynamicityTest method testInsertDynamicityEnabledCollectionOnly.
@Test
public void testInsertDynamicityEnabledCollectionOnly() {
assertEquals(0, testCollection.count());
mongo.getDatabase("otherDB").drop();
db.getCollection("otherCollection").drop();
assertFalse("The otherDB database should not exist", StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false).anyMatch("otherDB"::equals));
String body = "{\"_id\": \"testInsertDynamicityEnabledCollectionOnly\", \"a\" : \"1\"}";
Map<String, Object> headers = new HashMap<String, Object>();
headers.put(MongoDbConstants.COLLECTION, "otherCollection");
Object result = template.requestBodyAndHeaders("direct:dynamicityEnabled", body, headers);
MongoCollection<BasicDBObject> dynamicCollection = db.getCollection("otherCollection", BasicDBObject.class);
DBObject b = dynamicCollection.find(new BasicDBObject("_id", "testInsertDynamicityEnabledCollectionOnly")).first();
assertNotNull("No record with 'testInsertDynamicityEnabledCollectionOnly' _id", b);
b = testCollection.find(new BasicDBObject("_id", "testInsertDynamicityEnabledDBOnly")).first();
assertNull("There is a record with 'testInsertDynamicityEnabledCollectionOnly' _id in the test collection", b);
assertFalse("The otherDB database should not exist", StreamSupport.stream(mongo.listDatabaseNames().spliterator(), false).anyMatch("otherDB"::equals));
}
use of com.mongodb.BasicDBObject in project querydsl by querydsl.
the class MongodbQueryTest method asDBObject.
@Test
public void asDBObject() {
MorphiaQuery<User> query = query();
query.where(user.firstName.eq("Bob"), user.lastName.eq("Wilson"));
assertEquals(new BasicDBObject().append("firstName", "Bob").append("lastName", "Wilson"), query.asDBObject());
}
use of com.mongodb.BasicDBObject in project querydsl by querydsl.
the class MongodbSerializerTest method collectionIsNotEmpty.
@Test
public void collectionIsNotEmpty() {
BasicDBObject expected = dbo("$nor", dblist(dbo("addresses", dblist()), dbo("addresses", dbo("$exists", false))));
assertQuery(QUser.user.addresses.isNotEmpty(), expected);
}
use of com.mongodb.BasicDBObject in project querydsl by querydsl.
the class MongodbSerializerTest method collectionIsEmpty.
@Test
public void collectionIsEmpty() {
BasicDBObject expected = dbo("$or", dblist(dbo("addresses", dblist()), dbo("addresses", dbo("$exists", false))));
assertQuery(QUser.user.addresses.isEmpty(), expected);
}
use of com.mongodb.BasicDBObject in project jetty.project by eclipse.
the class MongoTest method main.
public static void main(String... args) throws Exception {
Mongo m = new Mongo("127.0.0.1", 27017);
DB db = m.getDB("mydb");
Set<String> colls = db.getCollectionNames();
System.err.println("Colls=" + colls);
DBCollection coll = db.getCollection("testCollection");
BasicDBObject key = new BasicDBObject("id", "1234");
BasicDBObject sets = new BasicDBObject("name", "value");
BasicDBObject upsert = new BasicDBObject("$set", sets);
WriteResult result = coll.update(key, upsert, true, false);
System.err.println(result.getLastError());
while (coll.count() > 0) {
DBObject docZ = coll.findOne();
System.err.println("removing " + docZ);
if (docZ != null)
coll.remove(docZ);
}
}
Aggregations