Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What do BSONObjects return when using a get method in Java?

Say I have a Mongo document that looks like this

{'_id' : NumberLong(123),
'sites' : [{'One',1}, {'Two',2}]
}

If I have a BSONObject in Java that maps this, say boop, would a BSONObject or a converted to a Java native object be returned if I return a field value?

For example, boop.get('sites') would return a BSONObject that represents an array or a Java list<Map<String,Integer>>?

Edit:

Documentation in the Mongo Java Driver says that the method returns an Object. I am going to assume that it means a converted object, like in a JSON library, but I want to make sure.

like image 222
user1002563 Avatar asked Jun 07 '26 05:06

user1002563


1 Answers

If I understood your question correctly, then the type of boot.get('sites') will be BasicDBList

db.testing.findOne()
{ "_id" : 1, "x" : [ 1, 2, 3 ] }

db.getCollection("testing").findOne().get("x") instanceof BasicDBList : true
like image 187
Abhishek Kumar Avatar answered Jun 08 '26 19:06

Abhishek Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!