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
39
votes
2 answers

How can I build an $or query for MongoDB using the Java driver?

I'm trying to Or some conditions in MongoDB (using the Java driver). This is what I'm doing : Pattern regex = Pattern.compile("title"); DBCollection coll = MongoDBUtil.getDB().getCollection("post_details"); BasicDBObject query = new…
MoienGK
  • 4,544
  • 11
  • 58
  • 92
13
votes
3 answers

Bulk Upsert with MongoDB Java 3.0 Driver

In the earlier versions of MongoDB Java drivers , to run a query and do unordered bulk upsert on the result all we had do was : BulkWriteOperation bulk = dbCollection.initializeUnorderedBulkOperation(); bulk.find(searchQuery).upsert().update(new…
void
  • 2,403
  • 6
  • 28
  • 53
12
votes
1 answer

How to speed up aggregation queries?

Following is the aggregation query : [ { "$match": { "UserId": { "$in": [ 5 ] }, "WorkflowStartTime": { "$gte": ISODate('2015-04-09T00:00:00.000Z'), "$lte":…
Ninad
  • 474
  • 8
  • 26
10
votes
2 answers

How can I log actual queries to MongoDB with mongo java driver

I want to see what queries mongo java driver produce, but I'm not able to do that. Using information from the official documentation I'm able just see in the log that update operation executes, but I don't see the query of this operation.
Deplake
  • 865
  • 2
  • 9
  • 22
10
votes
5 answers

MongoDb BSON stores Date in UTC time

If I try to put a date field in a Document (BSON) and write it to Mongo, BSON writes it in UTC. For example, a date DateTime dateTime = new DateTime("2015-07-01"); Document doc = new Document("date", dateTime.toDate()); will be stored as "date" :…
void
  • 2,403
  • 6
  • 28
  • 53
9
votes
1 answer

How could we make use of ClusterListener in Mongo?

I was trying to look for an example or usage of the ClusterListener to optimize and improve the debugging information of a service integrated with MongoDB Java client. How could this be used by us effectively to improve on our Mongo cluster set…
Naman
  • 27,789
  • 26
  • 218
  • 353
9
votes
2 answers

MongoDB BasicDBObject vs Document in java

I am using MongoDB v3.2.0 with Mongo Java Driver 3.0.4 version. I am using the BasicDBObject (deprecated) instead of using the Document in java, as I need to do many changes for converting to Document in my standalone java project. Can anyone tell…
Soorya Prakash
  • 921
  • 3
  • 9
  • 29
9
votes
1 answer

MongoException: java.lang.OutOfMemoryError: GC overhead limit exceeded

I am bulk writing to MongoDB and get an OOM exception (java.lang.OutOfMemoryError: GC overhead limit exceeded). I have two questions: Does the OOM come from the Mongo Client Driver or MongoDB Server? Is there a clue why the OOM happens? FO…
Tom
  • 5,848
  • 12
  • 44
  • 104
8
votes
3 answers

Get value from Embedded Document Mongo Java

I have the following document in mongo: > { "_id": ObjectId("569afce4b932c542500143ec"), > "date": "2016-1-17T2:31:0Z", > "day": NumberInt(17), > "model1": { > "date": "2016-01-17T02:31+0000", > "MondayModel": { > …
DevilCode
  • 1,054
  • 3
  • 35
  • 61
8
votes
5 answers

How to search a document and remove field from it in mongodb using java?

I have a device collection. { "_id" : "10-100-5675234", "_type" : "Device", "alias" : "new Alias name", "claimCode" : "FG755DF8N", "hardwareId" : "SERAIL02", "isClaimed" : "true", "model" : "VMB3010", "userId" :…
Swapnil1988
  • 269
  • 3
  • 6
  • 18
7
votes
5 answers

Java MongoDB save multiple documents at once

I Have a list of updated objects/documents i need save all the objects in the list at once. I saw save() in MongoTemplate but it can take single document at a time. Is there any way to save multiple documents at once or i need to call save in loop…
7
votes
3 answers

Change default Mongo connection pool size in spring-boot

I want to change the default size of connection pool provided by java mongodb driver which is 100 according to mongo docs. Below is the mongo client bean which I used to customize the connection pool size (refered this question). I set both min and…
wannix
  • 120
  • 1
  • 2
  • 12
7
votes
2 answers

Why eq doesn't exist for mongo-java-driver?

I've found in mongodb tutorial for java about how to query from mongo collection but the eq which they use doesn't work for me! Do you know how to filter documents from a collection with mongo and java? This is my try: package Database; import…
W W
  • 769
  • 1
  • 11
  • 26
7
votes
1 answer

MongoIterable.forEach vs. Iterable.forEach

MongoIterable.forEach requires a Block which is very similar to Java 8 Consumer. They are similar enough to cause problems, for example, the following doesn't compile: MongoIterable result =…
David Soroko
  • 8,521
  • 2
  • 39
  • 51
7
votes
3 answers

How to use MongoClientOptions instead of MongoOptions?

I am using MongoOptions class and its methods setFsync(boolean sync) setJ(boolean safe) setW(int val) setWtimeout(int timeoutMS) setSafe(boolean isSafe) How to achieve this using MongoClientOptions as MongoOptions is depracated in Mongo-Java-Driver…
Dev
  • 13,492
  • 19
  • 81
  • 174
1
2 3
23 24