Store an array using MongoDB and Java -
i saving basicdbobject in mongodb collection
basicdbobject[] abox = new basicdbobject[5]; basicdbobject obj = new basicdbobject(); obj.append("box", abox);
for moment void array have [] in collection
but when trying array
dbobject[] abox = (dbobject[]) obj.get("box");
i have error
java.lang.classcastexception: com.mongodb.basicdblist cannot cast [lcom.mongodb.dbobject;
do know how have array?
basicbdlist
list
, therefore has toarray
method. or keep list. should work:
list<basicdbobject> list = (list<basicdbobject>) obj.get("box"); basicdbobject[] abox = list.toarray(new basicdbobject[list.size()]);
Comments
Post a Comment