I am storing a mutable Set in mongoDB and now i want to retrieve that set from mongo but i am un able to do that maybe i am doing it in a wrong way here is my code
class A{
var genreIdSet = scala.collection.mutable.Set[Int]()
def addToGenreIdSet(genreId : Int) = {
genreIdSet += genreId
}
def getGenreIdSet : scala.collection.mutable.Set[Int]= {
genreIdSet
}
}
for storing in mongo
val result:WriteResult= collection.insert(new BasicDBObject("_id",artistImpl.getUuid)
.append("GetGenreIdSet",artistImpl.getGenreIdSet)
,WriteConcern.Acknowledged)
and i am retrieving like this
val cursor=collection.find()
var obj=new BasicDBObject
try {
while(cursor.hasNext)
{
obj=cursor.next().asInstanceOf[BasicDBObject]
id=obj.getString("_id").toInt
log.info("id value is "+id)
var a =obj.get("GetGenreIdSet").asInstanceOf[scala.collection.mutable.Set[Int]]
log.info("Set is "+a)
but it throws an error
-com.mongodb.BasicDBList cannot be cast to scala.collection.mutable.Set
java.lang.ClassCastException: com.mongodb.BasicDBList cannot be cast to scala.collection.mutable.Set
How can i resolve this issue please help me