I notice you haven’t had a response to this topic yet - were you able to find a solution?
If not then can you confirm if documents exist in your collection and can you share an example document?
Also,
Can you try your query in shell and check if you are getting the expected results?
By doesn't work do you mean that it never returns the expected value or are you seeing some other error?
Can you please share the exact error that you are getting? If it’s a casting error, then please refer to this thread which I think is related.
Additionally, I would recommend you to go through below thread and resources which includes some examples on querying database using reactive streams.
Thanks for your reply.
Im using now springframework with the ReactiveMongoTemplate and it works.
The answer is here click
And for the casting this was a helpful comment click
The only question I have now how do I use the variable in another method when it becomes available?
My exist method
public static boolean exists(String id) {
Query query = new Query(Criteria.where("UUID").is(id));
ReactiveMongoTemplate template = new ReactiveMongoTemplate(Database.getConnection(), "minecraft");
Mono<Boolean> exists = template.exists(query, "players");
exists.subscribe(
value -> {
Console.send(Database.PREFIX + value);
return value;
},
error -> Console.send(Database.ERROR + error)
);
And my method where I need the variable
public static Perk getPerks(Player player) {
Perk nullperk = new Perk("booster", "enterhaken", "rocket_jump", true, 6, 7);
if (!exists(player.getUniqueId().toString())) //here I need the variable
setPerk(player, nullperk);
if (Items.perks.containsKey(player))
return Items.perks.get(player);
return nullperk;