Reputation: 657
I have a BasicDBObject
which while debugging seems to hold:
{ "_id" : { "p_key" : { "$date" : "2012-02-02T00:00:00Z"} , "d_key" : 222} , "t_key" : 10195 , "w_key" : 4 , "f_key" : { "$date" : "2012-02-02T00:00:00Z"}}
Now, when I try:
dbObject.get("_id.d_key"));
I get a null pointer exception.
Any thoughts on what I am doing wrong here?
I am trying to get the value of d_key
inside _id
.
Upvotes: 2
Views: 1381
Reputation: 18595
DBObject and it's children do not support dot notation gets. You will have to do :
if(dbObject.containsField("_id"))
((DBOBject)dbObject.get("_id")).get("p_key")
That's an extremely large _id field by the way. It will result in huge indexes which is generally not a good idea.
Upvotes: 6