2

I'm storing elements with a Int64 field in MongoDb. I'm generating a value using all the bigfield and real 64 bits values.

Document looks like { fileds... messageUid : -3130564683773456202 }

No problem to write this long value with springboot-data.

Now I want to make a search on this value and SpringBoot-data returns nothing ...

findMessagesByMessageUid(long _messageUid) returns nothing.
findMessagesByMessageUid(Long _messageUid) returns nothing.

I've try in mongoShell directly 1 - find({messageUid: -3130564683773456202}) This is not working because the shell transform the number into a double and at end the value does not match exactly

2 - find({messageUid: NumberLong(-3130564683773456202)}) This is not working because the value is too large (there is a limit, I read that somewhere)

3 - find({messageUid: NumberLong("-3130564683773456202")}) This is working correctly

So I would like to know How to write the 3rd version of the query with SpringBoot-data

I've try different things around

@Query("{messageUid:NumberLong(?0)}")
public Message findMessageByMessageUid( long messageUid  );

=> JSON Parse exception on bootup

@Query("{messageUid:NumberLong(?0)}")
public Message findMessageByMessageUid( String messageUid  );

=> JSON Parse exception on bootup

Basically we can't use NumberLong in the @Query string.

I also tried

public Message findMessageByMessageUid( String messageUid  );

=> Return no matching document

Can someone tells me how can we make a working search on NumberLong with Spring-data ?

disk91
  • 31
  • 1

1 Answers1

0

Try this

@Query("{ 'messageUid' : NumberLong(?0) }")
public Message findMessageByMessageUid( Long messageUid  );
Ram
  • 1,743
  • 2
  • 18
  • 40
  • Not working : same Parsing issue : Caused by: com.mongodb.util.JSONParseException: { 'messageUid' : NumberLong("_param_0") } ^ at com.mongodb.util.JSONParser.read(JSON.java:301) ~[mongodb-driver-3.4.3.jar:na] – disk91 Mar 05 '18 at 09:29
  • What is `messageUid` data type? – Ram Mar 05 '18 at 11:10
  • It is Int64 data type – disk91 Mar 05 '18 at 13:13
  • You should use `Long` type in your repository method like this `public Message findMessageByMessageUid( Long messageUid );` From your error in comment, I believe you are using `String`. Please confirm – Ram Mar 06 '18 at 14:38
  • With Long I've got no value, exactly like with long. – disk91 Mar 07 '18 at 15:12
  • @disk91 - Did you found the solution? – PAA Mar 30 '20 at 13:45