top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

MongoDB Java driver find() returns exploded ObjectId?

+1 vote
480 views

Im just doing CRUD on a mongo database with Java. My problem is when I query the database

db.getCollection("something").find()

I get the documents correctly, but the ObjectId of each document is something like this:

"_id": {
  "timestamp": **********,
  "machineIdentifier": 16375804,
  "processIdentifier": 3908,
  "counter": 9920756,
  "time": 1459641911000,
  "date": "2016-04-03T00:05:11.000+0000",
  "timeSecond": **********
}

I need to get the 12-byte ObjectId, like this:

ObjectId("507f1f77bcf86cd799439011")

How do I do that?

posted Apr 5, 2016 by anonymous

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button LinkedIn Share Button
Can you provide a little more information -
* What version of the Java driver are you using?
* Was it the Java driver that created the ObjectId?
* How are you viewing that ObjectId? (printing it to stdout?)

Similar Questions
0 votes

My collection is like this, but I want to update a nested object with {"env":"qa"} in my updated collection with java-driver:

{ "_id" : ObjectId("5b052eeff9290437b217b1ed"), "app" : "hike", "group" : [ { "env" : "prod" }, { "env" : "test" } ]}{ "_id" : ObjectId("5b052f36f9290437b217b1ee"), "app" : "viber", "group" : [ { "env" : "prod" }, { "env" : "test" } ]}

+1 vote

Can we connect to MongoDB Server 2.6.12 using Java Driver version 0.11? We have a constraint of upgrading Java Driver version which would require huge change in our client code. We use JDK 8 for compilation of our project. We would like to know whether it is possible to connect to MongoDB Server 2.6.12 or MongoDB Server 3.0 using Java Driver version 0.11 if we only use the limited set of features (not the functionalities that were introduced in Server version 2.6.12 or 3.0).

+2 votes

From Mongodb client, we can use db.Collection.stats() to get status of collections, such as:

+ Number of records (count) 
+ Size on disk (storageSize) 
+ Indexes (indexSizes) 
+ Average object size (avgObjSize) 

Now I want to monitor these data from web backend with Mongodb java driver, please let me know how to get them?
I've referred: http://mongodb.github.io/mongo-java-driver/3.0/driver-async/getting-started/quick-tour-admin/ but it's not enough information for me. Any pointer?

0 votes

is it possible to create views using the Node.js MongoDB Driver (3.0)? There is no db.createView() in the drivers API reference.

...