Monday, January 8, 2018
mongodb Spring MongoRepository query adding class field to queries
mongodb Spring MongoRepository query adding class field to queries
mongodb - Spring MongoRepository query adding _class field to queries -
i have domain class called user. uses object of myuserid
id
@document(collection = "users") public class user implements serializable { @property @id private myuserid id; @version private integer version; private string firstname; // setters, getters }
the myuserid
class:
public class myuserid implements serializable{ @property private string userid; @property private string sampleid; // setters, getters }
inside mongo, documents getting stored {_id:{userid:....., sampleid:....}, <more fields here>}
my userrepository this:
public interface userrepository extends mongorepository<user, myuserid> { @query("{_id: {$in: ?0}}") list<user> findbyuserids(collection<myuserid> userids); }
when im querying userrepository, query beingness fired as:
{_id: {$in: [ {_class:"com.sampleuser.myuserid", userid:"....", sampleid:"...."}, {_class:"com.sampleuser.myuserid", userid:"....", sampleid:"...."}]}}
its obvious its adding _class field while querying, not while storing. can throw lite @ how prepare this? its causing queries fail. give thanks you!
there exists issue when using @query
whith complex id types. id suggest utilize custom repository implementation until datamongo-1078 resolved.
within custom implementation utilize mongotemplate
execute query somehow this
@override public list<user> findbyuserids(collection<myuserid> userids) { homecoming template.find(query(where("id").in(userids)), user.class); }
spring mongodb spring-data spring-data-mongodb
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.