I am trying to retrieve values of _id for inserted documents after successful InsertMany operation. To achieve this I am using InsertManyResult.getInsertedIds(). While this approach works most of the time there are cases where not all _id values are retrieved. I am not sure if I am doing something wrong but I…
Tag: mongodb
Spring Data Mongodb Query by embedded document id
i am trying to query a model that contains a @Reference as attribute like: and so on, then i have a query with more logic and code but in resume i have to filter by the field _id from Branch object, its just id on the object but on database its _id, ok no problem its normal behavior for the
How to write a query to get distinct values from mongodb collection?
I need to get distinct values from a collection. Those data is in a field of a collection. It means I need to get set of name from the user collection.I tried it using cmd and I get the result as I need. But I can’t understand how to write the query in the spring file.Since I’m new to java
How to custom sort only specific results in Spring MongoDB?
Is it possible to sort only results that matches a condition in Spring Mongo? Let us say I have this data: Color Fruit Amount Orange Orange 23 Red Apple 4 Red Strawberry 66 Yellow Banana 2 I want to sort the list to display the Fruits with color red on Top and the remaining fruits will be sorted by amount.
Using the MongoDb Java drivers is there a way to get Filters function dynamically
ie., Filters.search(“eq”, “name”, “Smith”) does the same thing as Filters.eq(“name”, “smith”) I’m writing some code that will search MongoDb depending on parameters passed in… So currently, my ugly code looks like I’m hoping there i…
How to query MongoDB with 2 conditions that has and relation
In my spring boot project, I am using MongoTemplate. My mongo document is Hotel looks this:- In my service class, I am trying to find as follows. My target is to find a hotel where the city name is an exact match and within a max price range. Following query don’t find anything. What is wrong? Answer ci…
Java MongoDB Authentication Verification
I am trying to find a way to create a gui login for a database application that uses MongoDB. The server is 3.6 and the Java driver is 4.1.1. I can connect to the database and perform all CRUD operations via the application. I’m getting a little confused out how to write a simple authentication gui inte…
Attempt to switch database target during SASL authentication
I try to setup a Mongo DB in Spring Boot project. I’ve set an uri in application.yml: But application fails to read data from repository with error: Line where error occurs (kotlin): where and The same error occurs with findAll and save operations on repository (and likely others too) Stack trace: I am …
MongoTimeoutException: No Server Match – MongoDB Atlas
For a few days now, I can’t connect to any of my MongoDB Databases that are hosted by Altas. I’m always getting a MongoTimeoutException Line 233-235 in Main Here is the class where I connect to the Database I replaced the user, password and database for this post. I already checked everything twic…
Panache with MongoDB find distinct
I have documents with “tags” arrays as properties. Now I want to query all distinct tag-items. Solution in mongo shell: which gives me: But how can I achieve the same result with Panache? The PanacheMongoEntity does not offer a specific distinct method. Nor do i know how to use the find method to …