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

Does findOneAndUpdate perform updates atomically? (As findAndModify is not available in Java MongoDB async driver)

I am using MongoDB's Java Async Driver version 3.6, I don't see a findAndModify implemented as part of MongoCollection Class (am I mistaken?), the closest thing is findOneAndUpdate can someone confirm that this operation will be performed…
amritanshu
  • 777
  • 13
  • 25
6
votes
4 answers

How to execute MongoDB native query (JSON) using mongo-java-driver only?

How to fire mongo native queries using java-mongo-driver only. No Spring-Data or EclipseLink or Hibernate OGM, Only using java-mongo-driver Sample query : db.orders.aggregate([ { $unwind: "$specs" }, { $lookup: { …
Charudatta Joshi
  • 119
  • 1
  • 1
  • 5
6
votes
1 answer

BackUp and restore db with MongoDB java driver

Is there any possibility in MongoDB java driver to make backUp and restore DB? My solution (just execute command) for now: public void makeBackUp(String path) { try { Runtime.getRuntime().exec("mongodump --out " + path); } catch…
Wsl_F
  • 832
  • 1
  • 7
  • 16
6
votes
2 answers

Mongo aggregation in java: group with multiple fields

I'm trying to perform an aggregation operation using in Java using the mongo-java-driver. I've performed some other find operations, but I'm unable to do the following aggregation correctly in Java: db.I1.aggregate([ { "$match": { "ci": 862222}…
Unai Sanchez
  • 496
  • 1
  • 6
  • 14
5
votes
1 answer

Getting unwanted output from MongoDB collation

I'm trying to sort the release versions in form of "a.b.c" I'm using mongo-java-driver org.mongodb mongo-java-driver 3.8.0 I have created the…
5
votes
2 answers

How to apply update using Filtered positional operator with arrayFilters

I am running on Mongodb 3.6, with mongo driver 3.4.3 and spring data mongo 1.5.10. Below is the structure of my document { "_id": 12345, "_class": "com.example.ProductRates", "rates": [ { "productId": NumberInt(1234), "rate":…
Kumaran
  • 125
  • 2
  • 6
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 driver cannot find public constructor for interface

I am using https://mongodb.github.io/mongo-java-driver-reactivestreams/1.11/. It seems to be using https://mongodb.github.io/mongo-java-driver/3.10/. I have a bunch of other registered classes that are working fine. I am using the suggestions at…
user1145925
  • 971
  • 3
  • 13
  • 24
4
votes
0 answers

Aggregation Pipeline mongoDB to mongoTemplate.executeCommand (Java - SpringBoot)

I'd like to use this working aggregation pipeline with mongoTemplate.executeCommand which takes as argument a String jsoncommand or a document command, but i can't find the damn syntax. pipeline : > db.getCollection('collectionName').aggregate([ {…
Frigg0
  • 125
  • 3
  • 9
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…
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
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
1 answer

MongoDB java driver Logging the queries

Using mongodb java driver: org.mongodb mongo-java-driver 3.2.2 We are using logback.xml file for logging…
vaibhav
  • 3,929
  • 8
  • 45
  • 81
1
2
3
23 24