Mongodb saves list of object

守給你的承諾、 提交于 2020-01-15 11:36:29

问题


I know how to save a list of String

Now, e.g. I create my own Animal class

But when I try to save list in mongodb, it gives

java.lang.IllegalArgumentException: can't serialize class Project

I do create a new mongo collection Animal, but it is still not working.


回答1:


You might check out Morphia or similar, where you can create object models and save them directly to Mongo.

http://code.google.com/p/morphia/




回答2:


If Animal class extend ReflectionDBObject then you can insert list of Animals.

Animal extends ReflectionDBObject {

}


来源:https://stackoverflow.com/questions/9551278/mongodb-saves-list-of-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!