use of com.mongodb.BasicDBList in project spring-data-document-examples by spring-projects.
the class MvcAnalyticsTest method groupQuery.
@Test
public void groupQuery() {
// This circumvents exception translation
DBCollection collection = operations.getCollection("mvc");
// QueryBuilder qb = new QueryBuilder();
// qb.start("date").greaterThan(object)
Calendar startDate = Calendar.getInstance();
startDate.clear();
startDate.set(Calendar.YEAR, 2010);
startDate.set(Calendar.MONTH, 5);
Calendar endDate = Calendar.getInstance();
endDate.clear();
endDate.set(Calendar.YEAR, 2010);
endDate.set(Calendar.MONTH, 12);
/*
* QueryBuilder qb = new QueryBuilder(); Query q =
* qb.find("date").gte(startDate
* .getTime()).lt(endDate.getTime()).and("action"
* ).is("addFavoriteRestaurant").build(); DBObject cond2 =
* q.getQueryObject();
*/
DBObject cond = QueryBuilder.start("date").greaterThanEquals(startDate.getTime()).lessThan(endDate.getTime()).and("action").is("addFavoriteRestaurant").get();
DBObject key = new BasicDBObject("parameters.p1", true);
/*
* DBObject dateQ = new BasicDBObject(); dateQ.put("$gte",
* startDate.getTime()); dateQ.put("$lt", endDate.getTime()); DBObject
* cond = new BasicDBObject(); cond.put("action",
* "addFavoriteRestaurant"); cond.put("date", dateQ);
*/
DBObject intitial = new BasicDBObject("count", 0);
DBObject result = collection.group(key, cond, intitial, "function(doc, out){ out.count++; }");
if (result instanceof BasicDBList) {
BasicDBList dbList = (BasicDBList) result;
for (Object element : dbList) {
DBObject dbo = (DBObject) element;
System.out.println(dbo);
}
}
System.out.println(result);
}
use of com.mongodb.BasicDBList in project Mycat-Server by MyCATApache.
the class MongoData method setGrouyBy.
public void setGrouyBy(DBObject gb) {
this.groupby = gb;
this.type = true;
if (gb instanceof BasicDBList) {
Object gb2 = ((BasicDBList) gb).get(0);
if (gb2 instanceof DBObject) {
for (String field : ((DBObject) gb2).keySet()) {
Object val = ((DBObject) gb2).get(field);
setField(field, getObjectToType(val));
}
}
}
}
use of com.mongodb.BasicDBList in project mongomvcc by igd-geo.
the class MongoDBVBranch method makeQueryObject.
private Map<String, Object> makeQueryObject() {
BasicDBList l = new BasicDBList();
String lba = MongoDBConstants.LIFETIME + "." + getRootCid();
String iba = MongoDBConstants.LIFETIME + ".i" + getRootCid();
// (1) check if there is information about the document's insertion
// available. if not just include this object.
// TODO this condition must be removed once we know the whole branching history
l.add(new BasicDBObject(iba, new BasicDBObject("$exists", false)));
if (!CompatibilityHelper.supportsAnd(getDB())) {
// (2) check if the object has been deleted after this commit.
// we use a $not here, so the query will also return 'true' if
// the attribute is not set.
l.add(new BasicDBObject(lba, new BasicDBObject("$not", new BasicDBObject("$lte", getHead()))));
} else {
BasicDBList l2 = new BasicDBList();
// (2) check if the object has been inserted in this commit or later
l2.add(new BasicDBObject(iba, new BasicDBObject("$lte", getHead())));
// (3) check if the object has been deleted after this commit.
// we use a $not here, so the query will also return 'true' if
// the attribute is not set.
l2.add(new BasicDBObject(lba, new BasicDBObject("$not", new BasicDBObject("$lte", getHead()))));
l.add(new BasicDBObject("$and", l2));
}
return Collections.unmodifiableMap(new BasicDBObject("$or", l));
}
use of com.mongodb.BasicDBList in project spring-data-mongodb by spring-projects.
the class MappingMongoConverter method removeTypeInfo.
/**
* Removes the type information from the entire conversion result.
*
* @param object
* @param recursively whether to apply the removal recursively
* @return
*/
@SuppressWarnings("unchecked")
private Object removeTypeInfo(Object object, boolean recursively) {
if (!(object instanceof Document)) {
return object;
}
Document document = (Document) object;
String keyToRemove = null;
for (String key : document.keySet()) {
if (recursively) {
Object value = document.get(key);
if (value instanceof BasicDBList) {
for (Object element : (BasicDBList) value) {
removeTypeInfo(element, recursively);
}
} else if (value instanceof List) {
for (Object element : (List<Object>) value) {
removeTypeInfo(element, recursively);
}
} else {
removeTypeInfo(value, recursively);
}
}
if (getTypeMapper().isTypeKey(key)) {
keyToRemove = key;
if (!recursively) {
break;
}
}
}
if (keyToRemove != null) {
document.remove(keyToRemove);
}
return document;
}
use of com.mongodb.BasicDBList in project spring-data-mongodb by spring-projects.
the class DefaultMongoTypeMapper method writeTypeRestrictions.
/*
* (non-Javadoc)
* @see org.springframework.data.mongodb.core.convert.MongoTypeMapper#writeTypeRestrictions(java.util.Set)
*/
@Override
public void writeTypeRestrictions(Document result, @Nullable Set<Class<?>> restrictedTypes) {
if (ObjectUtils.isEmpty(restrictedTypes)) {
return;
}
BasicDBList restrictedMappedTypes = new BasicDBList();
for (Class<?> restrictedType : restrictedTypes) {
Alias typeAlias = getAliasFor(ClassTypeInformation.from(restrictedType));
if (!ObjectUtils.nullSafeEquals(Alias.NONE, typeAlias) && typeAlias.isPresent()) {
restrictedMappedTypes.add(typeAlias.getValue());
}
}
accessor.writeTypeTo(result, new Document("$in", restrictedMappedTypes));
}
Aggregations