OpLogInfo in java Driver 3.2 vs 2.1

13 views
Skip to first unread message

majeed said

unread,
Apr 11, 2016, 9:29:11 AM4/11/16
to mongodb-user
Hi,

 i have the following concern :
 we had an application that used java driver 2.1 with the following code :

BasicDBObject object = (BasicDBObject) localDB.getCollection("system.namespaces").findOne(new BasicDBObject("name", "local.oplog.rs"));

LogFileSizeMB = ((BasicDBObject) object.get("options")).getDouble("size") / (1024 * 1024);

now after we moved to java driver 3.2 :

MongoCollection<org.bson.Document> collection = localDB.getCollection("oplog.rs");
MongoCursor<Document> cursor = collection.find().iterator();

the cursor always returning empty and we get the object as NULL.

can u please advise how can we change the implementation to get real data for setting OpLogInfo (log file size) ?

Regards,
Majeed Said

Ross Lawley

unread,
Apr 18, 2016, 3:58:58 AM4/18/16
to mongod...@googlegroups.com
Hi,

It looks like a simple issue, you aren't querying the same collection in 3.2

localDB.getCollection("system.namespaces") !=  localDB.getCollection("oplog.rs")

If you update the 3.2 code to:

import static com.mongodb.client.model.Filters.eq;

MongoCollection<org.bson.Document> collection = localDB.getCollection("system.namespaces");
Document object = collection.find(eq("name", "local.oplog.rs")).first();
LogFileSizeMB = object.get("options", Document.class).getDouble("size") / (1024 * 1024);

It should be the same.

Ross


--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.org/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/0962cdb1-7160-4759-9cf2-83a7bcc97876%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--


{ name     : "Ross Lawley",
  title    : "Senior Software Engineer",
  location : "London, UK",
  twitter  : ["@RossC0", "@MongoDB"],
  facebook :"MongoDB"}

Reply all
Reply to author
Forward
0 new messages