SpringSource/spring-data-mongodb — comment on commit caa245dd0899ff741d624c04835eb27407eb3acb
File:  line 0
By markpollack:

I have a few suggestions to mull through.

- This involves the least change. Shorten the 'andOperator' method on Criteria to be 'andOp' to improve readability since it is simply shorter. I'm usually not a fan of abbreviations in this case but it feels ok to me.

...

Query q = new Query(new Criteria().orOp(where("name").is("Sven").and("age").lt(50), where("age").lt(50), where("name").is("Thomas")));

- Have andOperator(Criteria... criteria), orOperator and norOperator become 'and', 'or', 'nor'. The current 'and(String key)' method becomes andWhere(String key). This breaks lots of code and is a bit less fluent for the common case of joining together multiple criteria.

...

Query q = new Query(new Criteria().or(where("name").is("Sven").andWhere("age").lt(50), where("age").lt(50), where("name").is("Thomas")));

- Have andOperator(Criteria... criteria), orOperator and norOperator become $and, $or and $nor. This seems to be bad form in Java land but I see it being used in the Casbah scala code that 10gen is now shipping.

...

trait AndOp extends BarewordQueryOperator {
def $and(fields: (String, Any)*) = {
val bldr = MongoDBList.newBuilder
for ((k, v) <- fields) bldr += MongoDBObject(k -> v)
MongoDBObject("$and" -> bldr.result)
}
}

In Java this would look like

Query q = new Query(new Criteria().$or(where("name").is("Sven").and("age").lt(50), where("age").lt(50), where("name").is("Thomas")));
Query q = new Query(new Criteria().$and(where("name").is("Sven"), where("age").lt(50)));
Query q = new Query(new Criteria().$nor(where("name").is("Sven"), where("age").lt(50), where("name").is("Thomas")));

or maybe also switch to use andWhere(String key)

Query q = new Query(new Criteria().$or(where("name").is("Sven").andWhere("age").lt(50), where("age").lt(50), where("name").is("Thomas")));

- Subclass of Critera such as AndCriteria, OrCritiera, and NorCriteria that has constructor args of (Criteria ...). Keep the 'and' method on Criteria as is

...

Query q = new Query(new AndCriteria(where("name").is("Sven"), where("age").lt(50)));

Thoughts?