0

I'm developing project with hibernate-ogm 5 with mongodb 3. But some query can not parsed. But I tested this query on shell. It works. What's wrong with this query?

com.mongodb.util.JSONParseException: 
db.Tree.update({'_id':2},{'$inc':{'totalUserCount':NumberInt(-1)}},{})
^
com.mongodb.util.JSONParser.parse(JSON.java:230)
com.mongodb.util.JSONParser.parse(JSON.java:155)
com.mongodb.util.JSON.parse(JSON.java:92)
com.mongodb.util.JSON.parse(JSON.java:73)
org.hibernate.ogm.datastore.mongodb.query.parsing.nativequery.impl.MongoDBQueryDescriptorBuilder.build(MongoDBQueryDescriptorBuilder.java:71)

screen shot

hurelhuyag
  • 1,691
  • 1
  • 15
  • 20
  • Have you tried running the query without the `NumberInt()` wrapper `db.Tree.update({'_id':2},{'$inc':{'totalUserCount': -1}},{})`? – chridam Apr 28 '16 at 10:08
  • @chridam if I remove NumberInt() wrapper MongoDB will change datatype to double. I don't want this behavior. – hurelhuyag Apr 28 '16 at 10:16

2 Answers2

2

FYI, the parsing issue will be fixed in the next release of OGM.

Note that it will support NumberLong but not NumberInt as NumberInt is not supported by the MongoDB Java Driver: https://jira.mongodb.org/browse/JAVA-2185 .

Guillaume Smet
  • 9,921
  • 22
  • 29
1

The use of functions like NumberInt is not supported at the moment.

I've created an issue for it: https://hibernate.atlassian.net/browse/OGM-1027

Davide D'Alto
  • 7,421
  • 2
  • 16
  • 30