1,043 questions
1
vote
1
answer
119
views
How globally configure conversion of `MongoTemplate.getCollection().aggregate()`'s result to POJO?
I know two separate APIs in MongoTemplate, if you want to perform an .aggregate:
By invoking directly functions in MongoTemplate, like MongoTemplate.aggregate()
By using an intermediate getCollection(...
0
votes
0
answers
43
views
How to view the complete aggregation statement when using spring data mongodb?
I just started using spring data mongodb aggregation query.
fun findRoot(): MarkdownMongoDocument? {
val aggregation = Aggregation.newAggregation(
MarkdownMongoDocument::class.java,
...
0
votes
1
answer
89
views
Quarkus MongoDB returns date 1970 if Java type is OffsetDateTime
MongoDB validation schema:
bsonType: "object",
required: ["createdAt"],
properties: {
createdAt: {
bsonType: "date"
}
}
Java class:
@Getter
@Setter
@...
-1
votes
1
answer
54
views
How to only get the last item of an array in MongoDB Document using Java/Kotlin
How to only get the last item of an array in MongoDB Document using MongoDB Java or Kotlin driver
Without loading the whole document or the list which can be very long
Let's say we have this data ...
1
vote
0
answers
528
views
Spring boot Mongo Data run long Transactional Method throw expceiton MongoCommandException: Command failed with error 251 (NoSuchTransaction)
I am currently utilizing Spring Boot 2.7.18 alongside the MongoDB sync driver. Within my codebase, there exists a transactional method called "updateCertCacheCollectionOld." This method is ...
0
votes
0
answers
117
views
Getting SSL error, while connecting to MongoDB via Java SDK, but works with Mongo Compass
Trying to connect to ec2-hosted mongodb replicaSet from my local machine. I am able to connect successfully via MongoDB Compass, but getting SSLException error when doing via debzium-mongo-source-...
0
votes
1
answer
48
views
MongoDb Java using sum() in Aggregations with literal value (not with reference)
This Java statement
Aggregation.group("name").sum("1").as("count")
generates
{"$group" : { "_id": "$name", "count": { "$sum&...
0
votes
1
answer
1k
views
Custom converter spring data mongodb
I'm trying to implement mu custom converter to be used in a specific find méthode.
So i implemented another mongoConfig with a custom mongoTemplate uses my custom converter as bellow.
Here my ...
1
vote
1
answer
143
views
Show storage engine config in mongosh
I've created a collection (in Java) with storage engine options where the block compressor should be zstd. How can I verify that .storageEngineOptions() worked as expected? Is it possible through ...
0
votes
1
answer
179
views
Java driver - BSON filter check if record is deleted?
I am trying to get valid records from mongodb using Spring - mongodb - java driver
my question is around the creation of the Bson filter
I am looking for matching records that match some filter (...
0
votes
1
answer
198
views
How to get property value direct from mongodb in JAVA
Hi everyone I have a collection of documents like bellow. I want to directly get "rights" from roles array for params: _id, groups._id, roles._id using java mongo driver.
{
"_id":...
0
votes
1
answer
472
views
Upgrading mongo-java-driver to Version 3.9.1
I am in the midst of upgrading the Spring version of one of our projects. As a result of this, the MongoDB library also had to be upgraded.
I am not able to track what the previous version of the ...
0
votes
0
answers
62
views
Get document from MongoDB containing all fields but only includes the first element of an array field
Consider a MongoDB collection with documents as follows:
[{
"_id": "123",
"name": "Bob",
"age": 23,
"properties": ["a&...
0
votes
1
answer
189
views
My Aggregation Query skip,order is not working propery with java
Here is my Java code. skip missing some records. also order is not working.
AggregateIterable<Document> propertiesDoc = collection.aggregate(Arrays.asList(
Aggregates.match(...
2
votes
1
answer
530
views
MongoDB Java Driver Filter Integer Value of a String
I have MongoDB Document parameter of type "real" number but is represented in the DB as a string- e.g "cId"="200" instead of "cId"=200I have to query the DB for ...
1
vote
2
answers
1k
views
Update MongoClient Credentials at runtime
I'm using spring-boot-starter-data-mongodb-reactive along with spring-cloud-vault-config-databases for dynamic secret rotations. Whenever the secret lease expires, I need to manually update the ...
6
votes
0
answers
402
views
Mongodb seems to be calling secondary when load increases
We have a mongo db replica set configuration with 1 primary and 2 secondaries. We have set the read preference to primary because one of our secondary is in a remote region and do not want read ...
0
votes
2
answers
506
views
MongoDB Java - Update every sub-array element using another field value
I have an existing collection, containing several documents:
[{
"_id": "1",
"someArray": [
{
"_id": "1.1"
&...
0
votes
0
answers
757
views
Mongodb Java - Update document replacing a string in field
I am looking for a way to update a document replacing a substring of a field with another value.
For example, in my database i have the following field:
{
"_id": 1,
"value":...
0
votes
1
answer
284
views
With the Java Sync MongoDB Driver, how do you acertain the impact of an aggregation pipeline?
I have code in Java that performs an aggregation pipeline roughly:
List<Bson> aggUpdate = Arrays.asList(
match(...),
project(...),
lookup(...),
...
merge(...)
);
AggregateIterable&...
0
votes
2
answers
904
views
Return only results of specific field - Mongodb java
Hello I am using MONGODB java driver version 4.5.1, I created a method to query a document and grab a specific field.
(id is a discord id not document _id)
final MONGODB mongodb = new MONGODB();
...
0
votes
1
answer
475
views
how to replaceOne document in MongoDb with Mongo database command
We have requirement to execute replaceOne operation with db.runCommand()
I checked list of commands from here, but i haven't found any command to replace one document.
Can someone please suggest us ...
0
votes
1
answer
3k
views
How to execute MongoDB shell command in Java application
I installed 4.4 version MongoDB and reproduced replica set, sharding for my Java application.
Now, I am looking for the approach of run MongoDB shell command in my Java application for check and ...
1
vote
1
answer
680
views
How to save alphanumeric sequence in mongodb and start generating from the last saved sequence in MongoDB
I have a method that generates an alphanumeric sequence based on a particular pattern. I want to save the generated sequence and when next I want to generate a new one, it should start from the last ...
-1
votes
1
answer
377
views
Morphia throws error when the field was changed its type from String to enum: No enum constant
In DAO class I use with Morphia I have replaced the String filed type to enums.Currency and I expect that everything will work fine, when the data is retrieved from the db:
was
public String ...
0
votes
1
answer
700
views
Invalid @BsonCreator constructor. Expected class java.lang.String, found interface java.util.List
I'm trying to use POJOs to write data to MongoDB, but I can't seem to get it working. I have a lot of different data structures because I'm storing various types of chart data.
Let's start with the ...
0
votes
1
answer
2k
views
MongoDB returning field as null
I am currently working on an application connected to a MongoDB instance. I am having trouble where the 'id' field of my object is not being returned to me within the application but is being returned ...
0
votes
1
answer
7k
views
Failed to target upsert by query :: could not extract exact shard key', details={}}.; nested exception is com.mongodb.MongoWriteException
We have recently moved to mongo java driver core/sync 4.4.0 from 3.12.1 with spring data mongo db from 2.2.5.RELEASE to 3.3.0 also spring boot version 2.6.2 and mongo server version 4.2.5
We are ...
0
votes
3
answers
1k
views
JSON parse error: Unrecognized field MongoDB Spring Boot
I am trying to save the following Java object as a document in MongoDB, here are my classes:
public class GenericIpConfig {
String connection_type;
String port;
String port_ingenico;
...
2
votes
1
answer
4k
views
Mongo java driver upgrade from 3.12.1 to 4.2.3 throwing method/class not found execptions on deployment
I have java application based on mongo server 4.2 and component versions are as follows
spring-boot 2.2.5.RELEASE
spring-data-mongodb2.2.5.RELEASE
mongo-java-driver3.12.1
I updated spring boot to 2.5....
1
vote
1
answer
158
views
How to keep Mongo db java driver logs into a file?
I'm using Mongo db java driver in order to perform some actions on my Mongo db server via my app.
when running my jar, the mongo db driver prints his logs to the screen.
I would like to stop the ...
0
votes
0
answers
51
views
Access data received by the HTTPs endpoint by my java console app
I'm using mongoDB to store and read data from my Java application. My application, in addition to working with the MongoDB database, works with an API for sending messages via whatsapp. Everything is ...
0
votes
1
answer
371
views
How to Set the URI for the ClusterSettings with codec in mongodb java driver
I am using the codec for the serialization and deserialization of POJO using 4.3/driver-reactive http://mongodb.github.io/mongo-java-driver/4.3/driver-reactive/getting-started/quick-start-pojo/
@...
1
vote
0
answers
729
views
Cannot find a public constructor for 'Optional' java mongodb driver
I have register codec registry for POJOs as below
@Singleton
public record Repository(MongodbConfiguration mongodbConfiguration) implements IRepository {
@Override
public <T> ...
0
votes
0
answers
297
views
MongoDB Java Reactive Streams lifecycle Micronaut
I'm trying to implement the life cycle events of a Java Reactive Streams MongoDB driver with Micronaut 3 application.
There is a requirement to perform BeforeInsert(), AfterInsert(), BeforeUpdate(), ...
1
vote
1
answer
890
views
CosmosDB - MongoDB API - 20 parallel transactions cause error (failed commit, transaction not active) using Java Spring @Transactional(readOnly=true)
We run into an odd problem when using Azure Cosmos DB with MongoDB API (4.0) and transactions. When we run exactly 20 parallel requests that all open a transaction that is read-only (no modifications),...
0
votes
0
answers
406
views
Deletion of 1 million records with BulkWrite (DeleteManyModel) taking longer time
I have collection of 5 million records and every time data refresh happens , i wanted to delete Approx. 1 Million records. I am using below java code but it taking 30 Sec to delete. that is to high ...
0
votes
1
answer
431
views
Tracing latencies for querying MongoDB using MongoDB java driver
I'm doing a perf test to analyze the performance of a application which uses the MongoDB. The application is written in java and it uses the MongoDB java driver to connect to cloud MongoDB instance.
I ...
0
votes
0
answers
80
views
Is it possible to kill a MongoDB query using the Java Async Driver
This ticket makes it seem like it is possible to kill Java queries via session identifier. https://jira.mongodb.org/browse/JAVA-1109
Does anyone know the relevant API in order to achieve this?
0
votes
0
answers
289
views
How to get bulk write metrics in MongoDB Java driver 3.0
I want to get bulk write metrics from Mongo server, like count of insertions, deletions, modifications, but the following methods always return 0.
BulkWriteResult.getInsertedCount()
BulkWriteResult....
0
votes
1
answer
380
views
Does aws documentdb validate mongodb client certificate for two way ssl?
How do we create client certificate to get validated by aws document db?In aws docs https://docs.aws.amazon.com/documentdb/latest/developerguide/connect_programmatically.html#connect_programmatically-...
1
vote
1
answer
2k
views
Do we still need Morphia for Java?
For my project I use Morphia, for easily mapping POJO objects to the Mongodb database. But in 2018 the mongo java driver started supporting pojo mapping it self and the Morphia project was abandoned ...
2
votes
2
answers
2k
views
mongodb-java POJO not returning id
I'm new to MongoDB and getting a bit crazy here. I'm using the latest mongo-java-driver version and dropwizard.
I use POJO to write to the DDBB, which works. However, when trying to get the element, I ...
1
vote
0
answers
607
views
MongoDb Cursor has been closed. Doesn't resume after db goes down
There are millions of exceptions for cursor closed in our application.
Cursor has been closed; nested exception is com.mongodb.MongoException: Cursor has been closed
It happens when for a moment ...
0
votes
0
answers
418
views
Storing a list of unknown objects in an pojo
What i want
I want to store a pojo with a list of objects as a json object into a collection. I do not know what objects are getting inserted into my pojo, thats why i need to keep it as generic as ...
1
vote
2
answers
519
views
How can I find the number of duplicates for a field using MongoDB Java?
How can I find the number of duplicates in each document in Java-MongoDB
I have collection like this.
Collection example:
{
"_id": {
"$oid": "...
1
vote
1
answer
1k
views
How I can count documents in collection MongoDB Java? [duplicate]
I have many documents in collection
So,How I can count documents in collection
1
vote
2
answers
2k
views
How to determine if a string can be used as a MongoDB ObjectID?
I am using Micronaut framework with JAVA and trying to validate the objectId with the below string.
60236833af6a1d49478d2bef // Valid mongo ObjectId
60236833a46a1d49478d2bef // Invalid mongo ...
0
votes
1
answer
1k
views
How to use $toLower and $trim aggregation operators using MongoDB Java?
I have a collection called Users, which contains an array called skills.
I use the following code to unwind the skills array and count the number of documents associated with each skill:
Bson uw = ...
0
votes
1
answer
1k
views
Mongo Connections pool is going beyond Scope
I am new to java and Mongo I am trying to set a max pool size of 100
I am running Load test in localhost
I am seeing that the pool is getting re-used without any issues but the max pool size is not ...