Questions tagged [mongo-java-driver]

The Java driver for MongoDB

The MongoDB Java Driver.

Using the Java driver is very simple. First, be sure to include the driver jar mongo.jar in your classpath.

The following code snippets come from the QuickTour.java example code that can be found with the driver source.

347 questions
3
votes
1 answer

Mongo Java Driver : How to create cursor in MongoDB by Cusor id returned by a db.runCommand

I am using db.runCommand(document) of Java Mongo driver api. Sample code I am using Document resultDocument = db.runCommand({ find: 'collectionName', filter: { startDate:{$gte:'#startDate',$lte:'#endDate'}}, projection: { _id:0}}); I…
PSS
  • 51
  • 4
3
votes
2 answers

In mongodb version 3 using java api how do we give a hint while querying

In mongodb version 3 using java api how do we give a hint while querying The query result is FindIterable which has MongoCursor. How should I give a hint to use a particular index. With older versions there is DBCursor which have API's for hint.
Devesh
  • 191
  • 1
  • 5
3
votes
1 answer

MongoDb Java driver - MongoException$Network: Read operation to server localhost:27017 failed

We started getting the below error intermittently during the last week. So far we could not trace this problem to anything in particular. The query in question is an aggregation to a collection which has around 400k objects. We have the same…
Eduardo Mayer
  • 359
  • 1
  • 3
  • 10
3
votes
1 answer

MongoClient not respecting connectTimeout

I am trying to set a connection timeout for the MongoClient (driver version 2.13). It hangs for 10 seconds then it times out. I need a fast timeout because this code is used in test. Here is my code: String connectionUri =…
thomas77
  • 1,100
  • 13
  • 27
2
votes
0 answers

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; so I've updated the SSL settings in that file: #…
2
votes
1 answer

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.8 hence made few changes to update dependencies…
2
votes
1 answer

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 mongoClient =…
2
votes
1 answer

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 and AppStatus. Below are the actions I want to…
Shibankar
  • 806
  • 3
  • 16
  • 40
2
votes
3 answers

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 bookmark managing app and rebuilding the backend…
Ian
  • 31
  • 1
  • 4
2
votes
2 answers

Mongo SORT with specific entry from list of attribute

I am working with Mongo aggregation/filter/sorting and limit with JAVA. I have below model objects. CustomPOJO is my database collection. @Document(collation = "CustomPOJO") public class CustomPOJO { public List valueList; …
Sagar Gangwal
  • 7,544
  • 3
  • 24
  • 38
2
votes
1 answer

Mongo Java Driver version mismatch with spring framework

I have springboot (2.0.4) application with Mongo Java driver version 3.11.2. When upgrading the application for mongo java driver to version 4.1.0 to use IAM authentication feature of new mongo java driver, the changes are breaking with overall…
2
votes
1 answer

Java MongoDB driver: How to update all Documents in Collection?

The following code allows us to update all documents in customerDetail collection where customer_user_id is 1: db.getCollection("customerDetail") .updateMany(Filters.eq("customer_user_id", 1), Updates.combine( …
user471011
  • 7,104
  • 17
  • 69
  • 97
2
votes
1 answer

Mongo DB to filter a Document if the field of an array has same value across all elements using mongo java driver

I need to fetch the document from the db, data is as below { "systemName": "ABC", "systemUsageAttrs" : [ { "cpuUsage": 30, "memUsage": 40, …
2
votes
3 answers

Java8 - How does explicit type matches one variant - not other type?

I have a simple snippet as below. I referred this List list = new LinkedList(); FindIterable itr = collection.find(findQuery) .forEach((Document doc) -> list.add(doc)); return list; It compiles…
Gibbs
  • 21,904
  • 13
  • 74
  • 138
2
votes
0 answers

Mongodb Timeseries Data Schema Design

Have been reading a few blogs related to this topic like https://www.mongodb.com/blog/post/time-series-data-and-mongodb-part-1-introduction. It seems storing related time-series data within a few (or single document) would be a better approach over…
Isaac Wong
  • 288
  • 3
  • 10