I tried to 'push' a document to an array of an existing document:
.where(_._id eqs id)
.modify(_.team.subfield(_.size) inc 1)
.modify(_.team.subfield(_.members) push member)
member is of type 'BsonRecord'. So the code above compiles without a problem but at runtime the following happens:
json can't serialize type : class com.mycompany.model.TeamMemberDoc
java.lang.RuntimeException: json can't serialize type : class com.mycompany.model.TeamMemberDoc
at com.mongodb.util.JSON.serialize(JSON.java:261)
at com.mongodb.util.JSON.serialize(JSON.java:141)
at com.mongodb.util.JSON.serialize(JSON.java:141)
at com.mongodb.util.JSON.serialize(JSON.java:58)
at com.mongodb.BasicDBObject.toString(BasicDBObject.java:84)
at com.foursquare.rogue.MongoHelpers$MongoBuilder$.buildModifyString(MongoHelpers.scala:124)
at com.foursquare.rogue.BaseModifyQuery.toString(Query.scala:800)
So basically the member document is handed down to the JSON serialization (from the MongoDB Java client) which of course has no clue what to do with it.
I think Rogue should call '.asDBObject' before that, if it detects that the argument is a 'BsonRecord'.
What do you think?