w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
In Spring-data-Mongodb, I'm not able to specify limit values to limit the number of results

Using the repository abstraction allows you to add a Pageable parameter (will be automatically picked up for query execution) to the method signature.

@Query(value = "{location :{ $nearSphere :{$geometry : {type :
"Point", coordinates : [?1, ?0] },  $maxDistance :?2}}")
List<User> search(float latitude, float longitude, float radius,
Pageable page);

Once you've got that in place you can simply call it via

//get the first 10 matching results
userRepository.search(37.802066, -122.377347, 10, new PageRequest(0,10));

You can find some more samples for special parameter bindings and geo queries in the reference manual.

© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.