342 questions
0
votes
0
answers
141
views
java.lang.ClassNotFoundException: org.apache.flink.api.connector.sink2.Sink$InitContext
I'm trying to develop Flink java api maven program which inserts several documents into MongoDB. I use the following Flink environment.
Flink: 2.0
MongoDB: 8.0
OS: Windows 11
JDK: 17.0.2
pom.xml:
&...
0
votes
0
answers
112
views
Upgrading Mongo java-driver to 5.x
while upgrading mongo-driver to 5.x getting following error while connecting mongo DB.
Caused by: java.lang.ClassNotFoundException: com.mongodb.internal.TimeoutSettings
at java.base/jdk.internal....
0
votes
1
answer
496
views
Upgrading mongo-java-driver:3.12.14 to mongodb-driver-sync:4.11.1 gives NoClassDefFoundError
I am trying to upgrade mongo-java-driver:3.12.14 to mongodb-driver-sync:4.11.1. After making all the necessary changes and resolving compilation errors, i am getting this runtime issue of ...
0
votes
1
answer
105
views
Missing Method in Mongo Legacy Java Driver
Previously we were using mongo-java-driver 3.10.2 there is a getAddress() method in MongoClient derived from the super class, Mongo. We needed to switch to mongo-driver-legacy 4.11.1 to be able to ...
0
votes
0
answers
210
views
How to connect to mongodb service running with kerberos authentciation using mongo-java-driver
I'm not much aware of kerberos.Kerberos server is running on an ec2 instance,on another ec2 instance,installed kerberos client and mongodb 6.0.2 enterprise and mongo shell 1.10.6.I created user ...
1
vote
1
answer
359
views
Java BsonArray to json string
How can I convert a Java (/Scala) BsonArray to a json string?
If I have
val array = new BsonArray()
array.add(new BsonInt32(1))
array.add(new BsonInt32(2))
it would be nice if "array.toJson"...
0
votes
1
answer
131
views
MongoDB: Apply Bson Update Query to Document Object
This might be a slightly unconventional scenario, but let me explain my situation. I have multiple clients that communicate with a central server. These clients send Bson queries to the server, which ...
0
votes
1
answer
3k
views
How to fix "class UUID cannot be cast to class String"
I'm storing a UUID in Mongo DB and when I want to read it again from MongoDB with
UUID.fromString(document.getString("userId"))
I get:
class java.util.UUID cannot be cast to class java.lang....
-1
votes
1
answer
150
views
Getting issue Upgrading from Mongo driver version 3.8.1 to 4.6.1
After updating the mongo driver version from 3.8.1 to 4.6.1. I am getting below error in my existing queries
"Unrecognized pipeline stage name: '$and'"
All the aggregations were working ...
1
vote
1
answer
405
views
How to write a groovy script to get _id from MongoDB
@Test
public void test() {
int userId = Math.abs(new Random().nextInt() % 10) + 1
HTTPResponse response = request.GET("http://127.0.0.1:8030/feed-server/feed/" + {userId} + "?...
0
votes
1
answer
595
views
Spring Mongo - Connecting to Multiple Mongo DB's results in Connection Timeouts
I have a problem which has me stumped. Hoping someone can help me here.
So I'm sadly in the position of having a micro-service which for the moment needs to connect to 4 mongo databases all running in ...
0
votes
1
answer
211
views
Why Micronaut Test closed the MongoClient connection
I'm about testing using MongoDB. Instead of Micronaut Test Resources I'm using local hosted docker container for database (I prefer to see the result).
Many my tests depends on MongoDB but some throws ...
0
votes
1
answer
397
views
Java MongoDB bulk insert from stream
I'm trying to insert a few million documents into MongoDB in one operation. Using MongoCollection.insertMany does not work for me because it takes a List as input and my data does not fit in memory.
...
1
vote
0
answers
56
views
mongo-java-driver update each item of array field belonging to document applying some conditional logic
I'm working on an event collection, where each document is modeled like so:
{
"event_name": "John Doe Concert",
"event_date": "2022-01-01"
"ticket_types&...
0
votes
1
answer
232
views
Mongo java driver add fields value population from indexOfArray
db.collection.aggregate([
{
$match : { filterQuery}
},
{
$addFields :{ “customGradeOrder” : { $indexOfArray: [ [“Gold”, “Silver”, “Bronze”] , “$grade” ] }}
},{$sort : { customGradeOrder : 1 } }
]);
...
0
votes
1
answer
242
views
Filter embedded Array object in mongodb document using Java driver
I have the below data, and I want to filter the data for _id = "63283dd5777142017baa763b" and subCategory._id = "63283e25777142017baa7641"
{
"_id": ObjectId("...
2
votes
0
answers
2k
views
MongoDB connection URI for SSL
I'm working on JDK8 and using mongo-java-driver(v3.5.0) to connect MongoDB(v3.6.3).
I've enabled SSL by following this article. I don't have /etc/mongod.conf file, instead I've /etc/mongodb.conf file; ...
1
vote
0
answers
2k
views
failed to access class com.mongodb.client.internal.MongoClientDelegate from class com.mongodb.Mongo
I am upgrading my spring boot application from 2.2.7.RELEASE to 2.6.7. In this application i am using mongodb 2.2.12.RELEASE and mongodb-java-driver 3.8.2. application build successfully but when I ...
1
vote
0
answers
1k
views
java.lang.IllegalAccessError: tried to access class org.bson.BSON from class com.mongodb.DBObjectCodec
We are trying to update our spring boot to 2.7.1.
We have old mongo java dependencies as
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</...
0
votes
1
answer
175
views
Is there a possible memory problem with lookup array in Java?
I am experimenting with Java and MongoDB and I am making a lookup aggregation. I noticed that when I perform a lookup the document returned contains the lookup field as an Array of documents - as a ...
0
votes
0
answers
244
views
MongoDB Java get Schema of existing collection using aggregation
I am looking for solutions to get field name and type for all nested fields including array of documents using $project $mergeobjects, $objectToArray , $unwind.
collection.aggregate(Arrays.asList(
...
0
votes
1
answer
286
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&...
1
vote
1
answer
502
views
Mongo Java: Set values and push to array with previous values in one command
I want to push the previous state (if the values changed) during an upsert into an array history (atomar) but no matter what I try, I can't find a clean solution.
Below you find simplified attempts:
...
0
votes
0
answers
178
views
Not able to store "_id" as a UUID string in Mongo java
I am trying to store _id as a String in Mongo, but for some reason, mongo is still overriding and storing it as an ObjectId. Below is my Java class
public class Subscription {
@JsonProperty(&...
0
votes
1
answer
958
views
org/bson/internal/CodecRegistryHelper with Micronaut data MongoDB
Using the latest Micronaut 3.4.1 with micronaut data and MongoDB. Keep getting the exception as java.lang.NoClassDefFoundError: org/bson/internal/CodecRegistryHelper
Gradle Dependencies
dependencies {
...
0
votes
1
answer
872
views
Java - storing Pojo with Path field in MongoDB
I'm using mongo-java-driver to store POJOs in MongoDB and so far I've had no issues, with doing just this:
CodecProvider pojoCodecProvider = PojoCodecProvider.builder().automatic(true).build();
...
0
votes
1
answer
702
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 ...
1
vote
0
answers
58
views
How to set read preference for gridFs in Java?
I want to connect my Java application with gridfs with read preference as secondaryPreferred, preferably using spring-data-mongodb 1.10.1
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
2k
views
Mongo change-Stream with Spring resumeAt vs startAfter and fault tolerance in case of connection loss
Can't find an answer on stackOverflow, nor in any documentation,
I have the following change stream code(listen to a DB not a specific collection)
Mongo Version is 4.2
@Configuration
public class ...
0
votes
1
answer
540
views
guarantee fields order in a mongodb documents using mongodb java driver
Using MongoDB driver 4.1.0 (and quarkus 1.1.1), I have an entity with a composite _id:
@BsonId
@JsonProperty("_id")
private CompositeId id = new CompositeId();
@Data
@AllArgsConstructor
@...
0
votes
1
answer
950
views
MongoDB incorrect BSON document format
I was trying to get the BSON document out of the MongoDB. As per the https://www.mongodb.com/json-and-bson , i am expecting the document received from the driver as :
{"hello": "world&...
1
vote
1
answer
1k
views
Mongo update multiple nested objects when their ID exists in a list
I'm trying to update many objects within a nested array when their IDs exist in a list.
The document structure is like so:
{
id: p00,
children: [{
id: c00,
value: true
...
1
vote
0
answers
670
views
java.lang.NoSuchMethodErrror:'com.mongodb.connection.ConnectionPoolSettings$Builder
I'm trying to use flapdoodle embedded mongodb for writing the unit tests. But I was receiving the following error. "java.lang.NoSuchMethodErrror:'com.mongodb.connection.ConnectionPoolSettings$...
0
votes
0
answers
290
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....
2
votes
1
answer
2k
views
MongoDB: java.lang.IllegalStateException: state should be: ClientSession from same MongoClient
I have an application that stores data in the used MongoDB Atlas (Cluster Tier:
M0 Sandbox Shared RAM, 512 MB Storage) collection as a transaction. The sample code is as follows.
MongoClient ...
0
votes
0
answers
1k
views
How to successfully connect to kerberos authenticated mongod instance from java application?I'm getting exception initializing GSSAPI Credentials
I've started mongod instance in kerberos auth mode.I'm able to connect from mongo shell.While connecting from java application,I get the following exception:
Key for the principal mongodb/****@**** ...
0
votes
0
answers
336
views
Can I make a MongoDB Text Index on a field in a Document that is nested in another Document? (Java)
I have a document that has a nested document set as the "name" variable:
Document{{name=Document{{he=דמטריוס הכרונוגראף, en=Demetrius the Chronographer}}}}
It is contained in a mock database ...
0
votes
1
answer
2k
views
java.lang.ClassCastException on collect() of ArrayList<Document>
I am trying to search through a mongo database to find a user given search term in one of the fields:
@GetMapping(value = {"/classes/search/{term}"})
public String className (
...
0
votes
1
answer
692
views
How can I log actual queries to MongoDB with mongo java driver in Micronaut application
I am setting the mongo logger as below
<logger name="org.mongodb" level="debug"/>
When I run the query using java driver in Micronuat application
DEBUG org.mongodb.driver....
1
vote
0
answers
775
views
Alternative for Deprecated DBCollection.save() method
After upgrading mongo dependency, the save() method no longer exists. What's the alternative?
Old:
DBObject dbObject = new BasicDBObject(items);
DBCollection dbCollection = ...
3
votes
0
answers
1k
views
Not able to Connect to Mongo Atlas Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=UNKNOWN,
I am trying to connect my java bot to Mongo Atlas but facing this error
com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting to connect. Client view of cluster state is {type=...
0
votes
2
answers
756
views
MongoDB 4.4, Java driver 4.2.3 - InsertManyResult.getInsertedIds() not returning IDs for all inserted documents
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 ...
1
vote
0
answers
505
views
UpdateOneModel adds new fields to existing document in mongodb java-driver
I'm not a Mongo expert. I'm trying to update the complete document by replacing with the new one.
I have the following fields in the existing document in the collection
qid, column a, column b, column ...
2
votes
1
answer
3k
views
Java - Insert/Update with MongoDB collection bulkWrite
I am very new to MongoDB. Trying to understand the best option to perform Bulk Write in MongoDB. I want to periodically refresh my Application collection. The key's for documents are AppID, AppName ...
2
votes
1
answer
1k
views
What is replacement for mongodb oplog in aws document db to listen to changes in collection?
We use oplog collection(that is present in local database) in our code to check if an event happens on a specific db and fire an event in our code.But,as aws document db doesn't support oplog as ...
2
votes
3
answers
9k
views
MongoDB Java Driver 4.2.2 - java.lang.noSuchMethodError when chaining .iterator or .into with .find
I’m attempting to build my own application and backend API to further my understanding of the Mongo Java driver after completing the M220J course, but am running into a blocker.
Context
I’m creating a ...
0
votes
1
answer
2k
views
MongoDB Java Error: A pipeline stage specification object must contain exactly one field
I am trying to get result of this MongoDB query on java.
db.fileTree.aggregate([
{
$match: {
"_id": "6062144bb25e4809548ef246",
}
},
{
...
1
vote
2
answers
2k
views
How to read attributes out of multiple nested documents in MongoDB Java?
I need some help with a project I am planing to do. At this stage I am trying to learn using NoSQL Databases in Java.
I've got a few nested documents looking like this:
MongoDB nesting structure
Like ...
0
votes
1
answer
537
views
Mongo bulk replace with 200k+ operations
E.g. I have such documents in the collection:
{
"key": "key1",
"time": 1000,
"values": [] // this one is optional
}
I need to update the collection ...