﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-于吉吉的技术博客-随笔分类-NoSQL</title><link>http://www.blogjava.net/dongbule/category/46253.html</link><description>建造高性能门户网</description><language>zh-cn</language><lastBuildDate>Sat, 30 Jul 2011 14:34:27 GMT</lastBuildDate><pubDate>Sat, 30 Jul 2011 14:34:27 GMT</pubDate><ttl>60</ttl><item><title>浅述MongoDB的管理操作</title><link>http://www.blogjava.net/dongbule/archive/2011/07/30/355409.html</link><dc:creator>陈于喆</dc:creator><author>陈于喆</author><pubDate>Sat, 30 Jul 2011 10:23:00 GMT</pubDate><guid>http://www.blogjava.net/dongbule/archive/2011/07/30/355409.html</guid><wfw:comment>http://www.blogjava.net/dongbule/comments/355409.html</wfw:comment><comments>http://www.blogjava.net/dongbule/archive/2011/07/30/355409.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/dongbule/comments/commentRss/355409.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/dongbule/services/trackbacks/355409.html</trackback:ping><description><![CDATA[<div>&nbsp;&nbsp;&nbsp;&nbsp; 不知不觉房产系统已经使用MongoDB一年多了，记得一年多以前，正是NOSQL被热炒时，MongoDB更是作为NOSQL中的佼佼者，被炒得火烫，也应该就在当时被这股火烫着了，所以义无反顾的选择了MongoDB，现在想想当时确实有些冲动了，当时MongoDB的资料还是比较少，更别说中文资料了，后来还出现使用MongoDB成功应用的范例Foursquare的宕机事件。现在确实应该很感谢MongoDB为我们的系统服务了一年了，在这一年的时间里，确实出现过不少的小问题，特别是在管理操作上，我想这大概也是因为MongoDB在系统维护上不如Mysql那样有着各种的业界实践，往往就只能通过管理员自己去摸索。<br />
下面将在这一年的一些简单的管理操作做一下记录<br /><br /><div><div>&nbsp;&nbsp;&nbsp; <a href="#x1">Starting and Stopping Mongo</a></div> <div>&nbsp;&nbsp;&nbsp; <a href="#x2">Security and Authentication</a></div> <div>&nbsp;&nbsp;&nbsp; <a href="#x3">Monitoring and Diagnostics</a></div> <div>&nbsp;&nbsp;&nbsp; <a href="#x4">Backups</a></div> </div><br />
<div><strong><a target=""><span style="font-size: 12pt;">Starting and Stopping Mongo</span></a></strong><a target=""><a name='x1' id='x1'></a></a><strong><a target=""><span style="font-size: 12pt;"></span></a><br />
<br />
</strong><span style="background-color: #ccffcc;">MongoDB启动</span><strong><br />
</strong>
<div>对了，MongoDB在linux下是无需安装的，从官网上下载下安装包后解压，直接执行mongod，就可以启动MongoDB服务器，当然mongod还有很多的启动选择项，运行mongod --help就可以查看所有的选择项。<br />
<br />
-f [ --config ] arg&nbsp;&nbsp; configuration file specifying additional options<br />
一般来说，启动选择项可以直接写在在mongod后面，也可以指定配置文件，用文件来加载各种启动项，如<br />
/home/mongodb/bin/mongod --config /home/mongodb/conf/mongod.conf</div>
<strong><br />
</strong></div>
<img src="http://www.blogjava.net/images/blogjava_net/dongbule/46046/1.jpg" alt="" width="725" border="0" height="195" /></div>
<div>上面是一台测试机的启动选择项。<br />
<br />
dbpath = /home/mongodb/data<br />
&nbsp;&nbsp;&nbsp; 指定数据库的存储目录，如果不设置则以mongodb的根目录为目录，当MongoDB启动之后，在数据库的存储目录下会创建一个mongod.lock文件，它是用来记录当前的mongod的进程号，同时也用于区分各个mongod的进程实例，所以不同的mongod进程实例是不能用相同的dbpath。<br />
logpath = /home/mongodb/mongodb.log<br />
&nbsp;&nbsp;&nbsp; 指定日志输出的路径，如果没有设置logappend = true，系统会清除原来的日志记录，把已有的文件进行覆盖。<br />
logappend = true<br />
&nbsp;&nbsp;&nbsp; 日志以追加的方式进行记录<br />
bind_ip = 192.168.86.111<br />
&nbsp;&nbsp;&nbsp; 指定对外服务的绑定ip，这里指定内网的ip方式，如果外网无特殊的处理方式是无法进行连接。<br />
port = 27017<br />
&nbsp;&nbsp;&nbsp; 指定服务器的监听端口号，默认是27017，如果单个机器要运行多个mongod进程，则需要给每个进程指定不同的端口号。<br />
fork = true<br />
&nbsp;&nbsp;&nbsp; 指定以守护进程的方式来启动MongoDB，如果不指定，在启动mongod命令是加&#8220;&amp;&#8221;也是可以的。<br />
auth = true<br />
&nbsp;&nbsp;&nbsp; 启动mongodb客户端登录的认证机制。<br />
master = true<br />
&nbsp;&nbsp;&nbsp; 指定该机器为主从模式下的主机器。<br />
配置完配置文件后启栋mongod，启动时要盯着日志文件看，因为日志通常会告诉我们一些错误或警告的信息，这样能够更好的帮助我们了解和避免错误。<br />
<img src="http://www.blogjava.net/images/blogjava_net/dongbule/46046/2.jpg" alt="" width="729" border="0" height="94" /><br />
<br />
<div>这里给出了个提示，使用的是32位的Mongodb，所以MongoDB只是存储最大为2GB的数据。其实这个跟MongoDB的mmap机制有关，如果是64位则不会存在这种限制。<br />
请注意一定要盯着日志看<br />
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">tail&nbsp;</span><span style="color: #000000;">-</span><span style="color: #000000;">100f&nbsp;</span><span style="color: #000000;">/</span><span style="color: #000000;">home</span><span style="color: #000000;">/</span><span style="color: #000000;">mongodb</span><span style="color: #000000;">/</span><span style="color: #000000;">mongodb.log</span></div>
<br />
<div><span style="background-color: #ccffcc;">停止MongoDB</span></div>
<div>千万要强调的是千万不要使用kill -9去关闭mongod！这样数据库会不理一切直接杀死该进程，会使得数据文件损坏。<br />
稳妥的方法是使用kill -2 pid去关闭mongod，也就是当mongod进程接受到关闭指令后会等待当前运行操作或文件分配等操作完毕后，关闭所有打开的连接，并将缓存的数据刷新到磁盘后才正式关闭。<br />
最稳妥的方式是使用shutdown命令来结束<br />
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;use&nbsp;admin<br />
switched&nbsp;to&nbsp;db&nbsp;admin<br />
</span><span style="color: #000000;">&gt;</span><span style="color: #000000;">&nbsp;db.shutdownServer();</span></div>
<br />
<div><strong>Security and Authentication</strong><a name='x2' id='x2'></a><br /><strong>
<br />
</strong></div>
</div>
<div>打开mongodb.org的Security文档，第一句话就是 Running Without Security(Trusted Environment)，跟我们强调世界上没有什么百分百安全的环境，最好的安全是放在一个安全的环境中运行，这么无底气的话语未免也让人为它的安全担心，不过事实上MongoDB还是有安全认证模式的，只不过跟mysql对比起来有一点简陋。<br />
<br />
<span style="background-color: #ccffcc;">MongoDB的安全</span><br />
MongoDB目前只支持最基本的安全认证，如果我们开启了安全性检查，则只有数据库认证用户才能进行读写操作，当然我们还可以创建读写权限用户和只读权限用户，如果我们在admin的数据库中进行创建用户，那么admin中的用户就会被当作超级用户，超级用户可以读写所有的数据库，并且还可以进行特殊的管理操作，比如可以再创建其他用户关闭进程等操作。<br />
<br />
<span style="background-color: #ccffcc;">配置MongoDb用户认证</span><br />
根据官网上的例子，我们也来创建一个超级用户，一个test库中具有读写操作的普通用户，一个test库中只有读操作的普通用户。</div>
<br />
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">&gt;&nbsp;use&nbsp;admin<br />
switched&nbsp;to&nbsp;db&nbsp;admin<br />
&gt;&nbsp;db.addUser(</span><span style="color: #000000;">"</span><span style="color: #000000;">cyz</span><span style="color: #000000;">"</span><span style="color: #000000;">,</span><span style="color: #000000;">"</span><span style="color: #000000;">abc</span><span style="color: #000000;">"</span><span style="color: #000000;">)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">_id</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;:&nbsp;ObjectId(</span><span style="color: #000000;">"</span><span style="color: #000000;">4dba5fe7c6792ae30fea3c31</span><span style="color: #000000;">"</span><span style="color: #000000;">)</span><span style="color: #000000;">,</span><span style="color: #000000;"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">user</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">cyz</span><span style="color: #000000;">"</span><span style="color: #000000;">,</span><span style="color: #000000;"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">readOnly</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;:&nbsp;false</span><span style="color: #000000;">,</span><span style="color: #000000;"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">pwd</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">8658a5bf469e005b047560619ef0d51c</span><span style="color: #000000;">"</span><span style="color: #000000;"><br />
}<br />
&gt;&nbsp;use&nbsp;test<br />
switched&nbsp;to&nbsp;db&nbsp;test<br />
&gt;&nbsp;db.addUser(</span><span style="color: #000000;">"</span><span style="color: #000000;">cyz001</span><span style="color: #000000;">"</span><span style="color: #000000;">,</span><span style="color: #000000;">"</span><span style="color: #000000;">abc</span><span style="color: #000000;">"</span><span style="color: #000000;">)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">user</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">cyz001</span><span style="color: #000000;">"</span><span style="color: #000000;">,</span><span style="color: #000000;"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">readOnly</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;:&nbsp;false</span><span style="color: #000000;">,</span><span style="color: #000000;"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">pwd</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">7a597bef551027cc2161d5e0efe4049e</span><span style="color: #000000;">"</span><span style="color: #000000;"><br />
}<br />
&gt;&nbsp;db.addUser(</span><span style="color: #000000;">"</span><span style="color: #000000;">cyz002</span><span style="color: #000000;">"</span><span style="color: #000000;">,</span><span style="color: #000000;">"</span><span style="color: #000000;">abc</span><span style="color: #000000;">"</span><span style="color: #000000;">,</span><span style="color: #000000;">true)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">user</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">cyz002</span><span style="color: #000000;">"</span><span style="color: #000000;">,</span><span style="color: #000000;"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">readOnly</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;:&nbsp;true</span><span style="color: #000000;">,</span><span style="color: #000000;"><br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">pwd</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">2dde0a3777cd7dd92459a6c3f98afac6</span><span style="color: #000000;">"</span><span style="color: #000000;"><br />
}<br />
</span></div>
</div>
<div>这里cyz是在admin库中创建，属于超级用户，可以对所有库进行操作，在test库中创建的cyz001和cyz002属于test库的操作人员，只能对test库进行相应操作，记得要为安全验证生效需要将启动项auth设置为true。<br />
<br />
<span style="background-color: #ccffcc;">查看用户</span><br />
所有的用户信息都存储在每个数据库的db.system.users中，可以使用find()进行查看<br />
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">&gt;&nbsp;use&nbsp;admin<br />
switched&nbsp;to&nbsp;db&nbsp;admin<br />
&gt;&nbsp;db.system.users.find()<br />
{&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">_id</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;:&nbsp;ObjectId(</span><span style="color: #000000;">"</span><span style="color: #000000;">4dba5fe7c6792ae30fea3c31</span><span style="color: #000000;">"</span><span style="color: #000000;">)</span><span style="color: #000000;">,</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">user</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;:&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">cyz</span><span style="color: #000000;">"</span><span style="color: #000000;">,</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">readOnly</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;:&nbsp;false</span><span style="color: #000000;">,</span><span style="color: #000000;">&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">pwd</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;:&nbsp;<br />
<br />
</span><span style="color: #000000;">"</span><span style="color: #000000;">8658a5bf469e005b047560619ef0d51c</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;}</span></div>
<br />
其中的pwd是根据用户名和用户密码生成的散列值。<br />
<br />
<span style="background-color: #ccffcc;">修改用户</span><br />
不管是添加用户，修改用户密码，修改用户操作权限都使用addUser()来完成。删除用户可以用remove()来实现。</div>
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">&gt;&nbsp;db.system.users.find({</span><span style="color: #000000;">"</span><span style="color: #000000;">user</span><span style="color: #000000;">"</span><span style="color: #000000;">:</span><span style="color: #000000;">"</span><span style="color: #000000;">cyz001</span><span style="color: #000000;">"</span><span style="color: #000000;">})</span></div>
</div>
<br />
<div><span style="background-color: #ccffcc;">更多的安全考虑</span><br />
<br />
刚说了MongoDB的安全认证其实还是简陋的，所以我们还是有其他很多的安全考虑。<br />
1.比如说MongoDB传输协议是不加密的，如果需要加密的话，我们可以考虑使用ssh隧道或是他们的技术来对客户端和服务端之间的通讯进行加密。<br />
2.将MongoDB部署在只有客户端服务器才能访问到的环境，比如内网，vpn网络中，可以使用 bind_ip = 本机或内网 。<br />
3.如果确实需要将MongoDB暴露在外部环境可以考虑使用IPTABLES等技术进行访问限制。<br />
<br />
<div><strong>Monitoring and Diagnostics</strong><a name='x3' id='x3'></a><br />
<br />
<div>官网首先给我们推荐了mongostat监控工具，基本上mongostat可以作为一个外部观测MongoDB内部状态指标的工具，并且一秒更新一次，如果出现一些性能问题可以用这里入手进行分析。<br />
<br />
<img src="http://www.blogjava.net/images/blogjava_net/dongbule/46046/3.jpg" alt="" width="1144" border="0" height="122" /></div>
<br />
<div>这里的属性都可以通过mongostat --help进行查看，有几个列需要解释一下，可以帮助到我们发生性能问题时比较准备的找到定位。<br />
<br />
faults：这是一个重要的性能指标，显示你的机器每秒页面故障的数量，这个是mongoDB映射到虚拟地址空间，而不是物理内存，这个值如果飙高的话，可能意味着你的机器没有足够的内存来存储数据和磁盘的访问。<br />
flushes：每秒做了多少次fsync，表面多少次数据被刷新进了磁盘。<br />
mapped：是指mmap有多少数据量，也就是服务器的内存映射，其中包含了虚拟内存和常驻内存。<br />
locked：这个值表面全局写入锁占用了机器多少时间， 当放生全局写入锁时，所有的查询操作都将等待，直到写入锁的解锁，如果这个锁飙高有可能是你的程序那部分出现问题。<br />
idx miss：B树未命中的比例，这个应该是我们查询的命中的实时指数，一般在特定查询中会有用到。<br />
qr | qw：如果有太多的查询进行处理，它们就以一个队列的方式进行，如果这个值飙高的话，那么查询也会变得很慢，因为后面的队列必须等待前面的队列执行完毕，高并发时，一般队列值会升高。<br />
另外我们还可以在mongodb shell中进行检查，使用db.serverStatus()</div>
</div>
<img src="http://www.blogjava.net/images/blogjava_net/dongbule/46046/4.jpg" alt="" width="683" border="0" height="376" /></div>
<br />
<div>基本上db.serverStatus()跟mongostat 差不多，不过它显示的数据更为具体，它也有一个缺陷就是它的数据是静态的，不是实时的。<br />
<br />
<span style="background-color: #ccffcc;">Http Console</span><br />
其实mongodb还提供了一个跟直观的检测工具，在默认情况下，启动mongodb的同时还会启动一个http的服务器，用网页展示的信息比前两个工具来得更加直观，启动默认的监听端口为28017 http：//ip:28017<br />
<br />
<img src="http://www.blogjava.net/images/blogjava_net/dongbule/46046/5.jpg" alt="" width="1178" border="0" height="385" /></div>
<img src="http://www.blogjava.net/images/blogjava_net/dongbule/46046/6.jpg" alt="" width="1151" border="0" height="236" /><br />
基本上我们可以看到查询，复制，锁等等这些的情况，具体的参数还是上官网looklook，http://www.mongodb.org/display/DOCS/Http+Interface<br />
<div>当然了，我们还可以使用其他的专业监控软件进行监控，如nagios，cacti，这些都有mongodb的插件。<br />
<br />
<div><strong>Backups</strong><a name='x4' id='x4'></a><br />
MongoDB的备份机制还是不错的，备份的方式也是很多，这个并不比mysql要差。<br />
<br />
Shutdown and Backup<br />
关闭服务，直接把dbpath参数的目录进行备份，只需把所有的文件进行复制到其他地方就可以，不过如果这个备份是在服务启动时候做的话，有可能备份的文件会被损坏，虽然这种关闭服务的备份很有效也很安全，都效果相当不理想。<br />
<br />
mongodump &amp; mongorestore<br />
mongodump简直就是mysqldump的另一版，如果你使用过mysqldump那就再熟悉不过了，mongodbdump可以使用在各个客户端，对正在运行的mongodb服务做出查询，然后将所有查到的文本写入到客户端的磁盘。</div>
</div>
<img src="http://www.blogjava.net/images/blogjava_net/dongbule/46046/7.jpg" alt="" width="704" border="0" height="257" /><br />
<br />
<div><br />
除了mongodump，MongoDB还提供了从备份中恢复数据的工具mongorestore，mongorestore从mongodump获取结果，并将备份的数据插入到运行的MongoDB实例。</div>
<br />
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">./mongodump&nbsp;--db&nbsp;test&nbsp;--collection&nbsp;user&nbsp;--out&nbsp;-&nbsp;&gt;&nbsp;/home/chenyz/cyz.bson<br />
./mongorestore&nbsp;--db&nbsp;test&nbsp;--collection&nbsp;user&nbsp;--directoryperdb&nbsp;/home/chenyz/cyz.bson&nbsp;--drop&nbsp;cyz.bson</span></div>
<br />
<div>上面的例子中，指定了要备份的db和要备份的collection，--drop表明要在恢复前删除集合，否则，数据将和现有的集合数据合并。<br />
<br />
<span style="background-color: #ccffcc;">主从备份</span><br />
上面说的几种备份数据方式已经很灵活了，但都不及在从服务器上备份来得方便，从服务器的数据几乎是于主服务器进行同步，涉及到主从方面还有很多，从服务器备份就不放在这里讲了。<br />
<br />
<span style="background-color: #ccffcc;">修复</span><br />
遇到一些停电，或非法关闭mongodb，不合理备份文件的操作，往往会出现文件损毁的提示，幸好，mongodb内置的修复功能会试着去恢复损坏的文件。<br />
操作很简单，只需在启动mongod 加入 --repair启动项，系统就会将所有的文件导入忽略那些无效的文档然后进行导入，完成之后，会重新建立索引，数据量大的话需要花费很长的时间，因为所有的文件都需要进行验证，所有的索引都需要重建，另外修复数据库还能起到压缩数据的作用，闲置的空间，碎片在修复后会被重新回收进行使用。<br />
<br />
另外在shell中也可以直接进行repair操作<br />
<div style="background-color: #eeeeee; font-size: 13px; border: 1px solid #cccccc; padding: 4px 5px 4px 4px; width: 98%;"><!--<br />
<br />
Code highlighting produced by Actipro CodeHighlighter (freeware)<br />
http://www.CodeHighlighter.com/<br />
<br />
--><span style="color: #000000;">&gt;&nbsp;db.repairDatabase()<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #000000;">"</span><span style="color: #000000;">ok</span><span style="color: #000000;">"</span><span style="color: #000000;">&nbsp;:&nbsp;</span><span style="color: #000000;">1</span><span style="color: #000000;"><br />
}</span></div>
</div><img src ="http://www.blogjava.net/dongbule/aggbug/355409.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/dongbule/" target="_blank">陈于喆</a> 2011-07-30 18:23 <a href="http://www.blogjava.net/dongbule/archive/2011/07/30/355409.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MongoDB with Morphia</title><link>http://www.blogjava.net/dongbule/archive/2010/09/16/332218.html</link><dc:creator>陈于喆</dc:creator><author>陈于喆</author><pubDate>Thu, 16 Sep 2010 09:41:00 GMT</pubDate><guid>http://www.blogjava.net/dongbule/archive/2010/09/16/332218.html</guid><wfw:comment>http://www.blogjava.net/dongbule/comments/332218.html</wfw:comment><comments>http://www.blogjava.net/dongbule/archive/2010/09/16/332218.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/dongbule/comments/commentRss/332218.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/dongbule/services/trackbacks/332218.html</trackback:ping><description><![CDATA[<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->先感谢同事梁员外&lt;MongoDB with Morphia&gt;的技术分享,下面是一些相关的笔记,当然啦,在应用Morphia之前需要有MongoDB的使用经验.<br />
<br />
<strong>What is Morphia?</strong><br />
<br />
<strong>Morphia is a lightweight type-safe library for mapping your Java objects to/from MongoDB</strong><br />
<br />
简单的来说Morphia与MongoDB的关系就如Hibernate与关系数据库的关系, 是一个实现Java对象到MongoDB双向映射的类库。<br />
<br />
下面是摘自Morphia官方的简介,带有一定的广告性,呵呵<br />
<br />
Easy to use, and very lightweight; reflection is used once per type and cached.<br />
<br />
Annotations describe mapping behavior; there are no XML files.<br />
<br />
Provides Datastore and DAO&lt;T,V&gt; data access abstractions, or roll your own...<br />
<br />
Type-safe Query support<br />
<br />
Works with Guice, Spring, and other DI frameworks.<br />
<br />
Has many extension points to build on<br />
<br />
Does not store Null/Empty values (by default).<br />
<br />
GWT support (entities are just POJOs) --(GWT ignores annotations)<br />
<br />
Advanced mapper that allows raw conversion, void toObject(DBObject) or DBObject fromObject(Object)<br />
<br />
<p class="MsoNormal"><span style="font-family: 宋体;"><a href="http://code.google.com/p/morphia/downloads/list"><span style="font-family: 宋体;">下载</span><span> <span lang="EN-US">morphia.jar</span></span></a></span></p>
<p class="MsoNormal"><span style="font-family: 宋体;"><a href="http://code.google.com/p/morphia/downloads/list"><span><span lang="EN-US"><br />
</span></span></a></span></p>
<p class="MsoNormal"><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
</p>
将jar导入到工程后,看看mongodb和morphia的初始化<strong><br />
<br />
初始化Mongo(MongoDB Java Api)</strong>
<p class="MsoNormal"><!--[if !mso]>
<style>
v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style>
<![endif]--><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]--><img alt="" src="http://www.blogjava.net/images/blogjava_net/dongbule/morphia/image002.gif" width="360" height="65" /></p>
<p class="MsoNormal"><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
</p>
<p class="MsoNormal"><strong><span style="font-family: 宋体;">初始化Morphia</span></strong><strong></strong></p>
<img alt="" src="http://www.blogjava.net/images/blogjava_net/dongbule/morphia/image004.gif" width="408" height="68" />
<p class="MsoNormal"><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
</p>
<p class="MsoNormal"><span style="font-family: 宋体;">在mapPackage需要制定一系列的pojo类</span></p>
<p class="MsoNormal"><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
</p>
<p class="MsoNormal"><strong><span style="font-family: 宋体;">对POJO类进行存储操作</span></strong><strong></strong></p>
<p class="MsoNormal"><img alt="" src="http://www.blogjava.net/images/blogjava_net/dongbule/morphia/image006.gif" width="260" height="223" /></p>
<p class="MsoNormal"><img alt="" src="http://www.blogjava.net/images/blogjava_net/dongbule/morphia/image008.gif" width="278" height="173" /></p>
<p class="MsoNormal"><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
</p>
以上代码创建了两个领域Hotel,Address,前者为实体存在,有自己的生命周期,后者则为内嵌在实体之中,没有独立的生命周期, 关于这些注解的详细含义，以及Morphia提供的其他注解，请参见其官方文档。<br />
<br />
<br />
以下说说Morphia与Spring的结合
<p class="MsoNormal"><img alt="" src="http://www.blogjava.net/images/blogjava_net/dongbule/morphia/image009.png" width="587" height="175" /></p>
<p class="MsoNormal"><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
</p>
<p class="MsoNormal"><span lang="EN-US">com.***.cvus.dao.MorphiaBean 是自己封装的一个SpringBean类</span></p>
<div style="background-color: rgb(238, 238, 238); font-size: 13px; border: 1px solid rgb(204, 204, 204); padding: 4px 5px 4px 4px; width: 98%;"><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">class</span><span style="color: rgb(0, 0, 0);">&nbsp;MorphiaBean&nbsp;</span><span style="color: rgb(0, 0, 255);">extends</span><span style="color: rgb(0, 0, 0);">&nbsp;Morphia&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&#8230;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);">&nbsp;Mongo&nbsp;mongo&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">private</span><span style="color: rgb(0, 0, 0);">&nbsp;String&nbsp;dbName&nbsp;</span><span style="color: rgb(0, 0, 0);">=</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">public</span><span style="color: rgb(0, 0, 0);">&nbsp;Datastore&nbsp;getDataStore()&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">if</span><span style="color: rgb(0, 0, 0);">&nbsp;(</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.mongo&nbsp;</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 0);">||</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">this</span><span style="color: rgb(0, 0, 0);">.dbName&nbsp;</span><span style="color: rgb(0, 0, 0);">==</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">)&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;</span><span style="color: rgb(0, 0, 255);">null</span><span style="color: rgb(0, 0, 0);">;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: rgb(0, 0, 255);">return</span><span style="color: rgb(0, 0, 0);">&nbsp;createDatastore(mongo,&nbsp;dbName);<br />
&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&#8230;<br />
}<br />
</span></div>
<p class="MsoNormal"><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
</p>
<p class="MsoNormal"><span lang="EN-US">MorphiaBean的应用</span></p>
<img alt="" src="http://www.blogjava.net/images/blogjava_net/dongbule/morphia/image012.gif" width="444" height="174" />
<p class="MsoNormal"><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
</p>
<strong>DataStrore—查询语法<br />
<br />
直接ID查询:<br />
</strong><img alt="" src="http://www.blogjava.net/images/blogjava_net/dongbule/morphia/image014.gif" width="312" height="47" />
<p class="MsoNormal"><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
</p>
<p class="MsoNormal"><strong><span style="font-family: 宋体;">简单条件查询:</span></strong><strong></strong></p>
<p class="MsoNormal"><img alt="" src="http://www.blogjava.net/images/blogjava_net/dongbule/morphia/image016.gif" width="554" height="206" /><br />
<span style="font-family: 宋体;"><a href="http://code.google.com/p/morphia/downloads/list"></a></span></p>
<p class="MsoNormal"><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
</p>
<strong>DataStrore—保存\删除 语法<br />
<br />
保存<br />
</strong><strong></strong>
<img alt="" src="http://www.blogjava.net/images/blogjava_net/dongbule/morphia/image018.gif" width="204" height="80" /><br />
<p class="MsoNormal"><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
</p>
<p class="MsoNormal"><strong><span style="font-family: 宋体;">删除</span></strong></p>
<img alt="" src="http://www.blogjava.net/images/blogjava_net/dongbule/morphia/image020.gif" width="460" height="63" /><br />
<br />
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]--><strong>Query—复杂查询<br />
<br />
Filter方法:<br />
</strong><img alt="" src="http://www.blogjava.net/images/blogjava_net/dongbule/morphia/image022.gif" width="516" height="38" /><br />
<p class="MsoNormal"><img alt="" src="http://www.blogjava.net/images/blogjava_net/dongbule/morphia/image024.gif" width="556" height="35" /></p>
<p class="MsoNormal"><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
</p>
<p class="MsoNormal"><strong><span style="font-family: 宋体;">获取第一个数据</span></strong></p>
<img alt="" src="http://www.blogjava.net/images/blogjava_net/dongbule/morphia/image026.gif" width="145" height="20" /><br />
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
<p class="MsoNormal"><strong><span style="font-family: 宋体;">获取列表:</span></strong><strong></strong></p>
<img alt="" src="http://www.blogjava.net/images/blogjava_net/dongbule/morphia/image028.gif" width="167" height="13" /><br />
<br />
<!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]--><strong>Query—排序,分页<br />
<br />
排序</strong>
<p class="MsoNormal"><img alt="" src="http://www.blogjava.net/images/blogjava_net/dongbule/morphia/image030.gif" width="554" height="83" /></p>
<p class="MsoNormal"><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
</p>
<p class="MsoNormal"><strong><span style="font-family: 宋体;">分页</span></strong></p>
<img alt="" src="http://www.blogjava.net/images/blogjava_net/dongbule/morphia/image032.gif" width="732" height="22" />
<p class="MsoNormal"><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
</p>
<strong>UpdateOperaions—更新操作<br />
<br />
执行语句<br />
<br />
</strong><strong></strong><img alt="" src="http://www.blogjava.net/images/blogjava_net/dongbule/morphia/image034.gif" width="300" height="21" /><br />
<p class="MsoNormal"><!--[if gte mso 9]><xml>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:PunctuationKerning/>
<w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing>
<w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery>
<w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:Compatibility>
<w:SpaceForUL/>
<w:BalanceSingleByteDoubleByteWidth/>
<w:DoNotLeaveBackslashAlone/>
<w:ULTrailSpace/>
<w:DoNotExpandShiftReturn/>
<w:AdjustLineHeightInTable/>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:UseFELayout/>
</w:Compatibility>
<w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel>
</w:WordDocument>
</xml><![endif]--><!--[if gte mso 9]><xml>
<w:LatentStyles deflockedstate="false" latentstylecount="156">
</w:LatentStyles>
</xml><![endif]--><!--[if gte mso 10]>
<style>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:普通表格;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-parent:"";
mso-padding-alt:0cm 5.4pt 0cm 5.4pt;
mso-para-margin:0cm;
mso-para-margin-bottom:.0001pt;
mso-pagination:widow-orphan;
font-size:10.0pt;
font-family:"Times New Roman";
mso-fareast-font-family:"Times New Roman";
mso-ansi-language:#0400;
mso-fareast-language:#0400;
mso-bidi-language:#0400;}
</style>
<![endif]-->
</p>
<strong>updateQuery：查询条件（Class：Query）</strong><br />
<strong><br />
ops：更新操作（Class：UpdateOperations）</strong><br />
<br />
ops（ UpdateOperations ）参数的语法：<br />
<br />
http://code.google.com/docreader/#p=morphia&amp;s=morphia&amp;t=Updating<br />
<br />
<br />
<strong>@Embedded &amp; @Reference<br />
</strong><br />
http://code.google.com/docreader/#p=morphia&amp;s=morphia&amp;t=EmbeddedAnnotation<br />
<br />
http://code.google.com/docreader/#p=morphia&amp;s=morphia&amp;t=ReferenceAnnotation<br />
<strong></strong><strong></strong>
<br />
<br />
<p class="MsoNormal">----------------------------------------<br />
<br />
by 陈于喆&nbsp;</p>
<p class="MsoNormal">QQ:34174409<br />
Mail: chenyz@corp.netease.com
<br />
<br />
</p>
<img src ="http://www.blogjava.net/dongbule/aggbug/332218.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/dongbule/" target="_blank">陈于喆</a> 2010-09-16 17:41 <a href="http://www.blogjava.net/dongbule/archive/2010/09/16/332218.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>