use of com.mongodb.BasicDBObject in project openhab1-addons by openhab.
the class MongoDBPersistenceService method connectToDatabase.
/**
* Connects to the database
*/
private void connectToDatabase() {
try {
logger.debug("Connect MongoDB");
this.cl = new MongoClient(new MongoClientURI(this.url));
mongoCollection = cl.getDB(this.db).getCollection(this.collection);
BasicDBObject idx = new BasicDBObject();
idx.append(FIELD_TIMESTAMP, 1).append(FIELD_ITEM, 1);
this.mongoCollection.createIndex(idx);
logger.debug("Connect MongoDB ... done");
} catch (Exception e) {
logger.error("Failed to connect to database {}", this.url);
throw new RuntimeException("Cannot connect to database", e);
}
}
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 spring-data-document-examples by spring-projects.
the class ChartController method getTopRecommendedRestaurants.
public DBObject getTopRecommendedRestaurants(MongoTemplate mongoTemplate) {
//This circumvents exception translation
DBCollection collection = mongoTemplate.getCollection("mvc");
Date startDate = createDate(1, 5, 2010);
Date endDate = createDate(1, 12, 2010);
DBObject cond = QueryBuilder.start("date").greaterThanEquals(startDate).lessThan(endDate).and("action").is("addFavoriteRestaurant").get();
DBObject key = new BasicDBObject("parameters.p1", true);
DBObject intitial = new BasicDBObject("count", 0);
DBObject result = collection.group(key, cond, intitial, "function(doc, out){ out.count++; }");
return result;
}
Aggregations