Questions tagged [mongo-java]

Some useful links:

315 questions
0
votes
2 answers

mongoDB test the return value

I use mongoDB 3.0.1 in java application, I want to know how I can test the return value of DBCollection.insert(BasicDBObject), For exemple, if the insert is done show message1 if not show message2. I see that mongoDB use WriteResult as return and…
Amir Saadallah
  • 668
  • 1
  • 8
  • 19
0
votes
1 answer

How to change bucket name in MongoDB GridFS?

I am using Mongo-Java-Driver 3.0. How can i change bucket name from fs to new_name in MongoDB GridFS?
Dev
  • 13,492
  • 19
  • 81
  • 174
0
votes
1 answer

Mongo Data not expiring

I'm trying to insert a record in mongo that expires in sometime. getMessagesCollection().ensureIndex(new BasicDBObject("createdAt", 1), new BasicDBObject("expireAfterSeconds", 10)); I insert my data like this Map map = new HashMap(); map.put("_id",…
KS88
  • 147
  • 1
  • 1
  • 8
0
votes
1 answer

How do you execute java queries based on ObjectID.timestamp?

How do you query time based queries from the ObjectID.timestamp()? db.myCollectin.findOne()._id.getTimestamp() I've tried Date date = new Date(); BasicDBObject query = new BasicDBObject("timestamp", new BasicDBObject("$lt",…
stackoverflow
  • 18,348
  • 50
  • 129
  • 196
0
votes
1 answer

mongodb regex query performance issues

I am using mongo java client. I can see x100 slower queries when using regex as compared to normal query for same document. All documents are indexed on field used in query. How do i improve query performance when using regex for searching in…
0
votes
1 answer

What are the benefits of using MongoCredential class?

I am using mongo-java driver(2.12).Suppose I have multiple databases. Before 2.11 version (we use Mongo class), for authentication I need to create user in each database and then authenticate it using db.auth(). I came to know this can be achieved…
0
votes
1 answer

partially update fields in a document - findAndModify remove all other fields?

When using MongoTemplate - collection.findAndModify It will delete all document fields, and leave only the updated column/s. Why is that? How to partially update fields in a document? DBCollection collection =…
JavaSheriff
  • 7,074
  • 20
  • 89
  • 159
0
votes
1 answer

How to parse ISO Java date format for mongoDB

Here is a sample document { "userId" : "ABC, "timestamp" : ISODate("2014-09-03T22:07:01.261Z"), "body" : { "id" : "0082171", "name" : "XYZ", "palce":"Ind" }, } …
Amaresh
  • 3,231
  • 7
  • 37
  • 60
0
votes
2 answers

Java code for mongodb aggregation query

I am new to Java. I checked few examples having aggregate usage.But still having few doubt. db.employee.aggregate({$unwind: '$dp.fin.Record'}, {$match:{"dp.mon":"patch.metrics",'dp.fin.Record':{$exists:1}}}, {$group:{_id:…
Amaresh
  • 3,231
  • 7
  • 37
  • 60
0
votes
1 answer

Sort limit reached for field which has an index

I am trying to sort cursor by two fields "start" and "end". Both of them have indexes. This is the code attempting to sort. DBCursor cursor = store.colConcepts.find(q); cursor.addOption(Bytes.QUERYOPTION_NOTIMEOUT); BasicDBObject sortObj…
Pratik Patel
  • 1,305
  • 1
  • 17
  • 44
0
votes
1 answer

MongoDB - MongoJack find and remove

I am completely new to MongoDB and MongoJack. I have this collection called pbf { "_id" : ObjectId("541ea72044ae1b4043e9ccba"), "name" : "First civ game", "type" : "WAW", "numOfPlayers" : 4, …
Shervin Asgari
  • 23,901
  • 30
  • 103
  • 143
0
votes
2 answers

com.mongodb.util.JSON.parse limit when parsing JSON and specifying projection

I'm using com.mongodb.util.JSON and parse method to query a mongodb database. I'm facing an issue in a specific query where I want to choose specific fields to display. The mongoshell query : {{type:'exam'},{score:1,_id:0}} In Java : String…
Ismail Sen
  • 571
  • 2
  • 14
  • 27
0
votes
0 answers

MongoDb saving different value for the float numbers

I am trying to insert a document having a geocoordinate key with value [77.218624, 28.635101] but when I insert in mongodb from the shell I get this value in the database [ 77.21862400000001, 28.635101 …
Shalu
  • 251
  • 2
  • 4
  • 15
0
votes
1 answer

Taking hours to iterate 300 million mongo db records

I'm iterating over the whole mongo documents from a mongo slave using mongo java API. Mongo Server: 2.4.10 Number of records in slave: 300 million. I've one mongo master, one mongo slave. (No sharding done) The mongo slave gets replicated very high…
0
votes
2 answers

Unable to update Inner Arraylist object using Mongodb Java Driver

I have below document structure in mongodb database: { "_id" : ObjectId("52ec7b43e4b048cd48499b35"), "eidlist" : [ { "eid" : "64286", "dst" : NumberLong(21044), "score" : 0 }, { …
Galaxy
  • 743
  • 1
  • 8
  • 26