Some useful links:
Questions tagged [mongo-java]
315 questions
4
votes
3 answers
Mongo Java: How to serialize DBObject as JSON on file?
I have a document in MongoDB as
name: name
date_created: date
p_vars: {
01: {
a: a,
b: b,
}
02: {
a: a,
b: b,
}
....
}
represented as DBObject
All key, value pairs are of type String
I want to serialize…

daydreamer
- 87,243
- 191
- 450
- 722
3
votes
1 answer
Mongo ReflectionDBObject, map ALL embedded array's elements to a class;
I use Mongo with native Java driver (no 3rd party library/ORM). I have this:
public class Release extends ReflectionDBObject {
//other fields omitted
private List releaseDetailsByTerritory = new…

Shivan Dragon
- 15,004
- 9
- 62
- 103
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,…

Aman Kumar
- 58
- 1
- 7
3
votes
0 answers
MongoDb Document to POJO with Default Codec Registry gives 'null' values
I am trying to map Bson Document to POJO using available Codec Registry in MongoDb 3.7, But It was giving me null values. Works well if I just print out the Bson Document.
Run menthod
public void run(MlsMongoConfiguration configuration,…

sudarshan kakumanu
- 308
- 1
- 4
- 15
3
votes
1 answer
mongo + java + too many open files
I am using mongo-java2.4jar for communicating with the mongo server.
In my webapp i am using mongo=new Mongo("serverIp","port") where ever it is required and once the processing is complete, I am closing the mongo connection using mongo.close().
But…

azhar_salati
- 1,554
- 5
- 28
- 54
3
votes
1 answer
Getting nested Document from mongo db using java Driver
I need to create an Object graph for the documents in a collection.
I am able to get all the key-value pairs. Here is the code which does that:
import com.mongodb.*;
import java.util.*;
public class GetKeyValuePair {
public static void…

aditya_gaur
- 3,209
- 6
- 32
- 43
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
2 answers
MongoDB HostName/URI Configuration
Note this looks long, but provides context and lists my main questions at the bottom. I researched all parts and included references.
I used the Google Cloud Launcher to create a Mongo database. This created a replica set of two Mongo servers…

Matt Goodrich
- 4,875
- 5
- 25
- 38
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
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
Cannot cast BasicDBObject to [B
I have the following gridfs in a mongodb database:
db.outputFs.files.find()
{ "_id" : ObjectId("000000000000000000000001"), "chunkSize" : 261120, "length" : 232, "md5" : "42290309186cc5420acff293b92ae21d", "filename" : "/tmp/outputFs-01.tmp",…

Pedro Montoto García
- 1,672
- 2
- 18
- 38
3
votes
1 answer
How to find by partial binary over BinData field in mongodb?
I have a BinData field in my mongo and I need to make a find over it with partial information.
Let's say that the bindata that I have looks like this:
{ "_id" : ObjectId("5480356518e91efd34e9b5f9"), "test" : BinData(0,"dGVzdA==") }
If I do this…

Kuu
- 117
- 1
- 12
3
votes
0 answers
MongoClient timeout
I recenty updated to MongoDB 2.6.3 via Ubuntu debs and also switched to Mongo Client library 2.12.2; when I now execute
final MongoClient m = new MongoClient( "localhost" );
DB db = m.getDB( "test" );
System.out.println( db.getName( )…

Andreas
- 2,211
- 1
- 18
- 36
3
votes
2 answers
$elemMatch dosen't work after $unwind in MongoDB Aggregation Framework
I have a collection of the following data:
{
"_id" : ObjectId("51f1fcc08188d3117c6da351"),
"cust_id" : "abc123",
"ord_date" : ISODate("2012-10-03T18:30:00Z"),
"status" : "A",
"price" : 25,
"items" : [{
"sku" : "ggg",
"qty" :…

Phalguni Mukherjee
- 623
- 3
- 11
- 29
3
votes
3 answers
Mongodb Logs shows too many connections open
Why does mongodb logs show too many opened connections? It's showing me more than the maximum connection limit and number of current operations in db.
Also my primary refused to create more connections after reaching 819 limit. That time, the number…

user2638955
- 91
- 1
- 4