Announcement Announcement Module
No announcement yet.
MongoDB: $slice on embedded data throws MappingException Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • MongoDB: $slice on embedded data throws MappingException

    I have a problem with sliced access to some embedded data in my model.
    I use spring-data-mongodb-1.5.0.RELEASE.jar

    The model is like

    class A {
    List<A> members;
    and I need paged/sliced access to the embedded members variable.

    I use this query

    ObjectId objectId = new ObjectId("538f1403e4b0121de0831bd7");
    Query query = new Query(Criteria.where("_id").is(objectId));
    query.fields().slice("members", pageable.getOffset(), pageable.getPageSize());
    List<A> members = this.operations.find(query, A.class);
    The query shows itself (toString()) as
    Query: { "_id" : { "$oid" : "538f1403e4b0121de0831bd7"}}, Fields: { "members" : { "$slice" : [ 0 , 10]}}, Sort: null
    which looks valid from my point of view. Still, I get a
    Code: No id property found on class class [Ljava.lang.Integer;
    at ingMongoConverter.createDBRef(MappingMongoConverte
    at ingMongoConverter.toDBRef(MappingMongoConverter.ja va:302)
    at yMapper.createDbRefFor(
    at yMapper.convertAssociation(
    at yMapper.convertAssociation(
    at yMapper.getMappedKeyword(
    at yMapper.getMappedObjectForField( 36)
    at yMapper.getMappedObject(
    at e.doFind(
    at e.doFind(
    at e.find(
    at e.find(
    I think the query building should not run at all into createDBRef here, as it is a sliced query which does not required DBRefs at all.
    The problem might be in class
    in method
    protected DBObject getMappedKeyword(Field property, Keyword keyword)
    where a field
    boolean needsAssociationConversion = property.isAssociation() && !keyword.isExists();
    is set. It checks against "isExists", but not against something like "isSliced" (which does not yet exist) and therefore is evaluated to true and, as a cause,
    tries to convert the non-existing association which is, in this case, just the slice-directive (an integer array).
    When I set the variable needsAssociationConversion to false while debugging, as if a kind of isSlice-check was done, everything works fine.

    Is there another way to build my query or is this a bug?

  • #2
    Please, move your question to the StackOverflow - we are going to close this forum soon and rely on SO.
    We need to clean this forum (old unanswered question) before close it.

    Thanks for understanding