Some useful links:
Questions tagged [mongo-java]
315 questions
5
votes
1 answer
mongodb upsert from java: how to get _id of existing object?
I'm using the mongo-jackson-wrapper with java and MongoDB. I find an object by querying a field of mine (not the _id field), and then I need to know the _id field value, whether
the net result was an update or an insert. However, I get an…

bmargulies
- 97,814
- 39
- 186
- 310
4
votes
2 answers
Should my MongoDB DAOs request unique DB objects?
I'm using the standard MongoDB Java driver to roll my own DAOs. I'm aware that all of my DAOs can share the same Mongo instance, but should all of my DAOs accessing the same database share the same DB object or are there good reasons for a new DB…

HolySamosa
- 9,011
- 14
- 69
- 102
4
votes
1 answer
Check the index creation progress in mongo DB using java driver
I have around 10 millions of data in MongoDB. There is a requirement to add a new compound index. I used the following code to create the index. Using ensureIndex with option creation in background.
MongoStore.ads().ensureIndexes("MyCollection",…

Parveen
- 149
- 1
- 12
4
votes
1 answer
Mongo+Java+SocketTimeOut
I am using MongoDb and I am facing problems while reading the records from the DB.
I am able to get them in the cursor but when I try to get the records from the cursor using
cursor.hasNext() it gives me following…

azhar_salati
- 1,554
- 5
- 28
- 54
4
votes
0 answers
Mongo Cursor Hangs after first fetch
I am running a lookup query using aggregation pipeline.
While iterating over the cursor returned from aggregation execution, I have noticed that program hangs when Mongo sends getMore command. I believe this command is used to fetch next batch of…

Rachit Agrawal
- 685
- 4
- 13
- 35
4
votes
1 answer
MongoDB Atlas: user is not allowed to do action find on system.indexes
I'm using MongoDB Atlas and I've recently started to get this error on my MongoDB replica:
user is not allowed to do action [find] on [mydb.system.indexes]
Nothing really has changed, so I'm wondering what can be an issue. The user has readWrite…

yyunikov
- 5,719
- 2
- 43
- 78
4
votes
1 answer
Mongo cursorFinalizerEnabled performance effect
I'm using Spring Boot with Mongo 3.4 (in cluster with MongoS)
The mongo client options configuration has the option cursorFinalizerEnabled.
According to documentation, this flag allows to:
Mongo Template closes the cursors. Making this true, spawns…

Leonel
- 2,796
- 5
- 25
- 36
4
votes
2 answers
Querying data in MongoDB-Java to remove _id and show only specified field
I'm completing a Java project in Eclipse as part of my university assignment. One of the requirements of the project is to write data to a text file and read it back in, in another class. I've decided, however, to use MongoDB rather than text…

George
- 57
- 1
- 5
4
votes
4 answers
Bson pretty print using Java MongoDb driver
I am using the Mongo Aggregation Framework using the Java MongoDB driver, version 3.3. I have an aggregagtion pipeline, that is merely collection of type List. I am trying to find a way to pretty print each stage of the pipeline.
Calling the…

riccardo.cardin
- 7,971
- 5
- 57
- 106
4
votes
2 answers
java code gives error in mongodb while compiling
I am new to mongodb and i have the following code
import com.mongodb.*;
import com.mongodb.Block;
import com.mongodb.client.AggregateIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import…

Kawinesh S K
- 3,148
- 1
- 16
- 29
4
votes
0 answers
Spring Data MongoDB add _class column
I am using MappingMongoConverter for converting an object to DBObject. I need the _class field to be added to the converted object.
Bean code:

Sumeet Kashyap
- 143
- 4
- 15
4
votes
1 answer
Error is saving java.sql.Date in MongoDB
Not able to save java.sql.Date field using DBCollection.save()
Error : CodecConfigurationException: Can't find a codec for class java.sql.Date.
while insert() method has constructor having DBEncoder field.
DBCollection.insert(List extends…

Dev
- 13,492
- 19
- 81
- 174
4
votes
1 answer
How to update existing documents with Spring Data MongoDB type information after type renames?
I am using mongodb with spring and I have some subdocuments that are derived from one base class, mongo uses the '_class' property to find out what is the correct type to convert to, but now I have changed the package name and the collection still…

jacob
- 1,397
- 1
- 26
- 53
4
votes
1 answer
Do $sort works for sub array document
I have a collection which has a field of array kind. I want to sort on the basis of a field of sub-array but Mongo is not sorting the data.
My collection is:
{
"_id" : ObjectId("51f1fcc08188d3117c6da351"),
"cust_id" : "abc123",
"ord_date" :…

Phalguni Mukherjee
- 623
- 3
- 11
- 29
4
votes
1 answer
MongoDB Java: Finding objects in Mongo using QueryBuilder $in operator returns nothing
I have a JUnit rule called as MongoRule looks like
public class MongoRule extends ExternalResource {
private static final Logger LOGGER = LoggerFactory.getLogger(MongoRule.class);
private final MongoService mongoService;
public…

daydreamer
- 87,243
- 191
- 450
- 722