Questions tagged [mongo-java]

Some useful links:

315 questions
37
votes
3 answers

$push and $set in same MongoDB update

I'm trying to use MongoDB's Java driver to make two updates ($set and $push) to a record in the same operation. I'm using code similar to the following: BasicDBObject pushUpdate = new BasicDBObject().append("$push", new…
HolySamosa
  • 9,011
  • 14
  • 69
  • 102
36
votes
5 answers

(MongoDB Java) $push into array

I'm using mongo 2.2.3 and the java driver. My dilemma, I have to $push a field and value into an array, but I cant seem to figure out how to do this. A sample of my data: "_id" : 1, "scores" : [ { "type" : "homework", "score" :…
notorious.no
  • 4,919
  • 3
  • 20
  • 34
25
votes
8 answers

How to aggregate by year-month-day on a different timezone

I have a MongoDB whom store the date objects in UTC. Well, I want to perform aggregation by year,month day in a different timezone (CET). doing this, works fine for UTC: BasicDBObject group_id = new BasicDBObject("_id", new BasicDBObject("year",…
SQL.injection
  • 2,607
  • 5
  • 20
  • 37
22
votes
5 answers

MongoDB Java API slow reading peformance

We are reading from a local MongoDB all documents from a collections and performance is not very brillant. We need to dump all the data, don't be concerned why, just trust it's really needed and there is no workaround possible. We've 4mio documents…
ic3
  • 7,917
  • 14
  • 67
  • 115
21
votes
5 answers

Executing Mongo like Query (JSON)through Java

I was wondering if there is a way to execute mongo like query directly through Java i.e. we give mongoDB like query as a String to a function in Java driver for mongoDB as a String Object and an DBCursor Object is returned. Something like: import…
aditya_gaur
  • 3,209
  • 6
  • 32
  • 43
18
votes
6 answers

How do I update fields of documents in mongo db using the java driver?

References: http://www.mongodb.org/display/DOCS/Java+Tutorial Still pretty new to mongo db but I'm trying to update part of an existing document inside a collection... unfortunately, the link above doesn't have an update example. Essentially, i…
longda
  • 10,153
  • 7
  • 46
  • 66
17
votes
5 answers

how to check from a driver, if mongoDB server is running

I wonder, if there is a way to check if mongoDB server is running from java driver for mongoDB? According to the tutorial, I can do Mongo m = new Mongo(); // or Mongo m = new Mongo( "localhost" , 27017 ); // and DB db = m.getDB( "mydb" ); But how…
zmila
  • 1,651
  • 1
  • 11
  • 13
17
votes
3 answers

Difference between cursor.count() and cursor.size() in MongoDB

What is the difference between the cursor.count() and cursor.size() methods of MongoDB's DBCursor?
Byter
  • 1,132
  • 1
  • 7
  • 12
16
votes
4 answers

how to prevent logging on console when connected to mongodb from java?

I followed this mongodb documentation. Here is my code public class JMongoDBCDemo { MongoClient mongoClient; DB db; DBCollection coll; public JMongoDBCDemo() { MongoClient mongoClient = new MongoClient( "localhost" ,…
prasad
  • 1,277
  • 2
  • 16
  • 39
15
votes
2 answers

Mongo opens too many connections

I am trying to write a lot of data to MongoDB, in a Java loop. I am getting errors based on the number of connections open. My theory is that since MongoDB is not transactional, lots of connections can be opened simultaneously. However the Java code…
Ankur
  • 50,282
  • 110
  • 242
  • 312
14
votes
4 answers

mongodb issue in java with limit and sort

Collection:progs { "_id" : "ABC", "defaultDirectory" : "abc", "defaultRecvDirectory" : "abc" } { "_id" : "RAS", "defaultRecvDirectory" : "recv/ras" } { "_id" : "SND", "defaultSendDirectory" : "send/snd" } In the mongo…
Franck
  • 1,754
  • 1
  • 13
  • 14
13
votes
2 answers

Mongo ISODate query in Java

I have a mongo query to be executed : query = { "dateField" : { "$gte" : ISODate('2011-11-10T07:45:32.962Z') } } When I do a db.Collection.find(query) on the mongo shell, I am able to retrieve the results. How could I query this using Java ? I…
Skynet
  • 657
  • 2
  • 9
  • 25
11
votes
4 answers

Retrieve sub-document in array as DBObject(s)

I'm very new to MongoDB, and I'm using it along with the Java driver. I have this document structure: { "_id" : ObjectId("4f7d2ba6fd5a306d82687d48"), "room" : "Den" } { "_id" : ObjectId("4f7d2baafd5a306d82687d49"), "room" : "Foyer" } { "_id" :…
Erik Dietrich
  • 6,080
  • 6
  • 26
  • 37
10
votes
8 answers

Serialize class for MongoDB model

When I insert a List into mongodb, there is a problem: Exception in thread "main" java.lang.IllegalArgumentException: can't serialize class mongodb.Person at org.bson.BasicBSONEncoder._putObjectField(BasicBSONEncoder.java:234) at…
NOrder
  • 2,483
  • 5
  • 26
  • 44
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
1
2 3
20 21