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
4
votes
1 answer

How to execute queries with both AND and OR clauses in MongoDB with Java?

I want to execute query in MongoDB 3.2 with Java Driver 3.2, which contains both $and and $or clauses at the same time. With the reference, I tried the following approach: List criteria1 = new ArrayList<>(); List criteria2 = new…
Mike
  • 14,010
  • 29
  • 101
  • 161
4
votes
6 answers

Connecting to MongoDB using jdbc driver

Purpose is to connect MongoDB remote server through JAVA: URL = "jdbc:mongo://" + serverIP + ":" + port+ "/" +databaseName; Class.forName("mongodb.jdbc.MongoDriver"); dbConn = getConnection(URL,mongo1,…
manoj
  • 41
  • 1
  • 1
  • 2
3
votes
0 answers

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=UNKNOWN, servers=[{address=localhost:27017,…
3
votes
0 answers

Backward compatibility of Springboot 2.3.4

I am using spring boot 2.0.4 for a project, and need to upgrade the mongo driver to version 4.1. I understand that springboot 2.3.4 upgrades (here) MongoDB to version 4.1, but it doesn't clearly says if it is MongoDB version or MongoDriver. Seems…
Nitin1706
  • 621
  • 1
  • 11
  • 21
3
votes
1 answer

Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. state = connected

I am trying simple CRUD on my mongo server and I am getting this one com.mongodb.MongoTimeoutException: Timed out after 30000 ms while waiting for a server that matches WritableServerSelector. Client view of cluster state is…
user3751481
  • 125
  • 2
  • 10
3
votes
3 answers

Type mismatch: cannot convert from MongoCollection to DBCollection

I am trying to upgrade spring-data-mongodb from 1.5 to 2.1.0.M3 so I modified the pom dependency from : org.springframework.data spring-data-mongodb
JavaSheriff
  • 7,074
  • 20
  • 89
  • 159
3
votes
1 answer

$push and $set in same MongoDB update for same array element in a document

The document structure looks like below - { "nestedDocArray" : [ { "a" : "a", "b" : "b", "c" : "c", "createdOn" : ISODate("2018-06-19T08:38:34.228Z") }, { "a"…
3
votes
2 answers

How to use Mongo Java driver @BsonCreator annotation?

I'm trying to map an immutable object from MongoDB to my Java POJO and i keep getting the following error: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.RuntimeException:…
nofunatall
  • 561
  • 6
  • 20
3
votes
1 answer

"Invalid BSON field name" during upsert

I'm trying to upsert data into a Mongo collection using the following code: val UsersColl = "Users" val UsersColl_AuthProvider = "AuthProvider" val UsersColl_UserId = "UserId" val UsersColl_Active = "Active" val UsersColl_SlackRealName =…
Glory to Russia
  • 17,289
  • 56
  • 182
  • 325
3
votes
1 answer

negative process id in object id

Add some records to collection with java driver, it will generate object id for each records automatically. In my database, it generate below Object Id by MongoDB: ObjectId("58b38cd57decdd8070b2df8f") Then I make a test for current object…
Kimi Liu
  • 33
  • 4
3
votes
1 answer

Spring mongo queries set custom timeout

I would like to lower the timeout setting in my spring-mongo java application (the query should fail after 300 ms if the database is not accessible). I tried this config: @Configuration public class MongoConfiguration { private String mongoUri =…
marie
  • 457
  • 8
  • 27
3
votes
0 answers

Dynamically create database in mongodb in java

Is there any way to dynamically create a new database in mongo using the 3.x Java driver along with adding a user with defined roles to it?
Mahesh Nathwani
  • 121
  • 1
  • 9
3
votes
1 answer

MongoSocketOpenException when starting MongoClient with mongo-java-driver

I'm running a java web server on Windows with a local MongoDB database using mongo-java-driver 3.2.2 When starting the server I create a new MongoClient: MongoClient mongoClient = new MongoClient("localhost:27017", options); (options contain some…
vicban3d
  • 131
  • 3
3
votes
1 answer

How to check if MongoDB connection is established with Java?

In my app, MongoDB 3.2.4 runs on a custom port, I want to implement logic where my app will try to reach MongoDB on a custom port and if it fails it will use the default 27018 port. In order to do that I use the following code: String mongoClientURI…
Mike
  • 14,010
  • 29
  • 101
  • 161
3
votes
2 answers

How to insert object in MongoDB 3.2 document?

I have a User public class User { private String name; private String email; public User () { } public User(String name) { this.name = name; } public User(String name, String email) { this(name); …
0xFF
  • 585
  • 1
  • 6
  • 22
1 2
3
23 24