4

I am using MongoDB with Spring Boot 2.0.1.RELEASE. Everything seems to be working fine. I am able to perform CRUD operations properly using MongoRepository. When I use mongodb query in like

@Query(value = "{address.city:?0}")
public List<Hotel> findByCity(String city);

@Query(value = "{address.country:?0}")
public List<Hotel> findByCountry(String country);

When I try to access data using the url localhost:8090/hotels/address/city/Rome, I get the following error in response

{
    "timestamp": "2018-05-04T04:51:43.549+0000",
    "status": 500,
    "error": "Internal Server Error",
    "message": "Invalid JSON input. Position: 9. Character: '.'.",
    "path": "/hotels/address/city/rome"
}

and the following log in console:

Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.bson.json.JsonParseException: Invalid JSON input. Position: 9. Character: '.'.] with root cause

org.bson.json.JsonParseException: Invalid JSON input. Position: 9. Character: '.'.

I don't know why I am getting Invalid JSON input. Position: 9. Character: '.'. when I am performing GET request?

Where am I going wrong?

thebluephantom
  • 16,458
  • 8
  • 40
  • 83
Pritam Bohra
  • 3,912
  • 8
  • 41
  • 72

2 Answers2

6

Missing quotes; @Query(value = "{'address.country':?0}")

– Neil Lunn

That worked for me too.

TuGordoBello
  • 4,350
  • 9
  • 52
  • 78
Kieveli
  • 10,944
  • 6
  • 56
  • 81
0

It can arise if you are missing quotes or it can be due to unparsed string passed to MongoDB. Try using parsed string like \"appname\":1. This is an example of projection.