Uploaded image for project: 'Spring Data MongoDB'
  1. Spring Data MongoDB
  2. DATAMONGO-602

Querying with $in operator on the id field of type BigInteger returns zero results

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 1.1.1
    • 1.3 GA, 1.2.4
    • None
    • The Road To SpringOne

    Description

      There is a problem when trying to query for documents with id field is in a given list of BigInteger values. Id field is mapped as a BigInteger.

      For example, these lines will work only if given id list contains only one item.

      List<BigInteger> profileIds = findProfileIds();
      Predicate predicate = QProfileDocument.profileDocument.id.in(profileIds);
      Iterable<ProfileDocument> profiles = profileRepository.findAll(predicate);
      

      The underlying MongodbQuery is different if there is only one item in profileIds. The query looks like this for a profileIds with multiple elements

      { "_id" : { "$in" : [ "25069473312490162649510603609" , "25045916045544535958655878835"]}}
      

      and it looks like this when there is only one item in the list.

      { "_id" : { "$oid" : "5100fb776c67e7e092be6b59"}}
      

      In the first case, query will return no results and in the second it will work and return an Iterable with one item.

      As you can see, the problem is with the representation of the BigInteger. using decimal format will not work with MongoDB.

      Attachments

        Activity

          People

            thomasd Thomas Darimont
            netke Nemanja Nedic
            Spring Issues Spring Issues
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: