protected DBObject get(ObjectId id, String collectionName) { return collection(collectionName).findOne(new BasicDBObject("_id", id)); }
protected <T extends Persisted> DBObject get(Class<T> modelClass, ObjectId id) { return collection(modelClass).findOne(new BasicDBObject("_id", id)); }
protected <T extends Persisted> DBObject findOne(Class<T> model, DBObject query) { return collection(model).findOne(query); }
protected DBObject findOne(DBObject query, DBObject sort, String collectioName) { return collection(collectioName).findOne(query, new BasicDBObject(), sort); }
protected <T extends Persisted> DBObject findOne(Class<T> model, DBObject query, DBObject sort) { return collection(model).findOne(query, new BasicDBObject(), sort); }
protected DBObject findOne(DBObject query, String collectionName) { return collection(collectionName).findOne(query); }
private Object getRefOps(Object ref) { // db.oplog.refs.find({_id: {$gte: {oid: %ref%}}}).limit(1) DBObject query = new BasicDBObject(MongoDBRiver.MONGODB_ID_FIELD, new BasicDBObject(QueryOperators.GTE, new BasicDBObject(MongoDBRiver.MONGODB_OID_FIELD, ref))); DBObject oplog = oplogRefsCollection.findOne(query); return oplog == null ? null : oplog.get("ops"); }
public boolean getBoolean(String key) { DBCollection coll = getCollection(); DBObject query = new BasicDBObject(); query.put("key", key); DBObject result = coll.findOne(query); if (result == null) { return false; } if (result.get("value").equals(true)) { return true; } return false; }
public BasicDBList getList(String key) { DBCollection coll = getCollection(); DBObject query = new BasicDBObject(); query.put("key", key); DBObject result = coll.findOne(query); return (BasicDBList) result.get("value"); }
@Override public <T> T get(final Class<T> clazz, final DBRef ref) { DBObject object = getDB().getCollection(ref.getCollectionName()).findOne(new BasicDBObject("_id", ref.getId())); return mapper.fromDBObject(this, clazz, object, createCache()); }
@Override public MongoEndpointProfile findByKeyHash(byte[] endpointKeyHash) { LOG.debug("Find endpoint profile by endpoint key hash [{}] ", endpointKeyHash); DBObject dbObject = query(where(EP_ENDPOINT_KEY_HASH) .is(endpointKeyHash)) .getQueryObject(); DBObject result = mongoTemplate.getDb() .getCollection(getCollectionName()) .findOne(dbObject); return mongoTemplate.getConverter().read(getDocumentClass(), result); }
@Test public void shouldSaveAnEntityWithNullPoints() { getDs().save(new City("New City", null)); DBObject storedCity = getDs().getCollection(City.class) .findOne(new BasicDBObject("name", "New City"), new BasicDBObject("_id", 0) .append("className", 0)); assertThat(storedCity, is(notNullValue())); assertThat(storedCity.toString(), JSONMatcher.jsonEqual("{ name: 'New City'}")); }
@Test public void testEnum() { final EnumEntity ee = new EnumEntity(); getDs().save(ee); final DBObject dbObj = getDs().getCollection(EnumEntity.class).findOne(); Assert.assertEquals(1, dbObj.get("val")); }
private void shouldFindField(final HasList hl, final List<String> expected) { getDs().save(hl); final DBObject dbObj = getDs().getCollection(HasList.class).findOne(); Assert.assertTrue("Should find the field", dbObj.containsField("names")); Assert.assertEquals(expected, getDs().find(HasList.class) .find(new FindOptions().limit(1)) .tryNext() .names); }
private void shouldFindField(final HasComplexObjectValuedMap hm, final Map<String, ComplexObject> expected) { final DBObject dbObj; getDs().save(hm); dbObj = getDs().getCollection(HasComplexObjectValuedMap.class).findOne(); Assert.assertTrue("Should find the field", dbObj.containsField("properties")); Assert.assertEquals(expected, getDs().find(HasComplexObjectValuedMap.class) .find(new FindOptions().limit(1)) .tryNext() .properties); }
private void shouldFindField(final HasMap hl, final Map<String, String> expected) { final DBObject dbObj; getDs().save(hl); dbObj = getDs().getCollection(HasMap.class).findOne(); Assert.assertTrue("Should find the field", dbObj.containsField("properties")); Assert.assertEquals(expected, getDs().find(HasMap.class) .find(new FindOptions().limit(1)) .tryNext() .properties); }
private void shouldFindField(final HasCollectionValuedMap hm, final Map<String, Collection<String>> expected) { final DBObject dbObj; getDs().save(hm); dbObj = getDs().getCollection(HasCollectionValuedMap.class).findOne(); Assert.assertTrue("Should find the field", dbObj.containsField("properties")); Assert.assertEquals(expected, getDs().find(HasCollectionValuedMap.class) .find(new FindOptions().limit(1)) .tryNext() .properties); }
private void shouldNotFindField(final HasComplexObjectValuedMap hm) { getDs().save(hm); DBObject dbObj = getDs().getCollection(HasComplexObjectValuedMap.class).findOne(); Assert.assertFalse("field should not exist, value = " + dbObj.get("properties"), dbObj.containsField("properties")); Assert.assertNull(getDs().find(HasComplexObjectValuedMap.class) .find(new FindOptions().limit(1)) .tryNext() .properties); }
private void shouldNotFindField(final HasMap hl) { getDs().save(hl); DBObject dbObj = getDs().getCollection(HasMap.class).findOne(); Assert.assertFalse("field should not exist, value = " + dbObj.get("properties"), dbObj.containsField("properties")); Assert.assertNull(getDs().find(HasMap.class) .find(new FindOptions().limit(1)) .tryNext() .properties); }
private void shouldNotFindField(final HasCollectionValuedMap hm) { getDs().save(hm); DBObject dbObj = getDs().getCollection(HasCollectionValuedMap.class).findOne(); Assert.assertFalse("field should not exist, value = " + dbObj.get("properties"), dbObj.containsField("properties")); Assert.assertNull(getDs().find(HasCollectionValuedMap.class) .find(new FindOptions().limit(1)) .tryNext() .properties); }