天天看点

mongodb-java-driver基本用法

2、下面是基本的CRUD示例代码:

其中,为了演示复杂对象的持久化,类UserData定义如下:

运行效果如下:

emp

system.indexes

{ "_id" : { "$oid" : "53d34795744ec171e7f6980a"} , "name" : "杨俊明" , "sex" : "男" , "address" : { "postcode" : "201202" , "street" : "田林路888号" , "city" : "上海"}}

{ "_id" : { "$oid" : "53d34795744ec171e7f6980a"} , "name" : "杨俊明" , "sex" : "MALE" , "address" : { "postcode" : "201202" , "street" : "田林路888号" , "city" : "上海"}}

{ "_id" : { "$oid" : "53d34796744ec171e7f6980b"} , "key" : "jimmy" , "value" : { "userName" : "jimmy" , "password" : "123456" , "pets" : [ "cat" , "dog"] , "favoriteMovies" : { "dragons" : "Dragons II" , "avator" : "Avator I"} , "birthday" : "May 1, 1990 12:00:00 AM"}}

延伸阅读:

<a href="http://docs.mongodb.org/ecosystem/drivers/java/" target="_blank">mondodb-java-driver 官方在线文档</a>

<a href="http://www.cnblogs.com/huangxincheng/category/355399.html" target="_blank">8天学通mongodb系列</a>

<a href="http://javacrazyer.iteye.com/blog/1840042" target="_blank">MongoDB基本用法</a>

<a href="http://www.lanceyan.com/tech/mongodb/mongodb_cluster_1.html" target="_blank">搭建高可用的MongoDB集群(上):MongoDB的配置与副本集</a>

<a href="http://www.lanceyan.com/tech/mongodb/mongodb_repset1.html" target="_blank">搭建高可用mongodb集群(二)—— 副本集</a>

<a href="http://www.lanceyan.com/tech/mongodb_repset2.html" target="_blank">搭建高可用mongodb集群(三)—— 深入副本集内部机制</a>

<a href="http://www.lanceyan.com/tech/arch/mongodb_shard1.html" target="_blank">搭建高可用mongodb集群(四)—— 分片</a>