﻿<?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-狼爱上狸-随笔分类-Mongo</title><link>http://www.blogjava.net/waterjava/category/48128.html</link><description>闻道有先后，术业有专攻！</description><language>zh-cn</language><lastBuildDate>Wed, 23 Mar 2011 06:47:10 GMT</lastBuildDate><pubDate>Wed, 23 Mar 2011 06:47:10 GMT</pubDate><ttl>60</ttl><item><title>mongo数据库的下载与安装（windows xp环境下）</title><link>http://www.blogjava.net/waterjava/archive/2011/03/23/346832.html</link><dc:creator>狼爱上狸</dc:creator><author>狼爱上狸</author><pubDate>Wed, 23 Mar 2011 03:00:00 GMT</pubDate><guid>http://www.blogjava.net/waterjava/archive/2011/03/23/346832.html</guid><wfw:comment>http://www.blogjava.net/waterjava/comments/346832.html</wfw:comment><comments>http://www.blogjava.net/waterjava/archive/2011/03/23/346832.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/waterjava/comments/commentRss/346832.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/waterjava/services/trackbacks/346832.html</trackback:ping><description><![CDATA[<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-weight: normal; font-style: normal; text-align: justify; border-collapse: collapse; font-size: 12px; ">1.下载数据库<a href="http://fastdl.mongodb.org/win32/mongodb-win32-i386-1.6.5.zip" style="color: #000000; text-decoration: none; outline-style: none; outline-width: initial; outline-color: initial; ">http://fastdl.mongodb.org/win32/mongodb-win32-i386-1.6.5.zip</a></p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-weight: normal; font-style: normal; text-align: justify; border-collapse: collapse; font-size: 12px; ">2.现在完成后解压目录，放到C盘下，然后按照如下选择&#8220;我的电脑-&gt;属性-&gt;高级-&gt;环境变量&#8221;，将&#8220;C:\mongodb\bin&#8221;这个路径放到环境变量内（如果添加环境变量可以去网上找）.</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-weight: normal; font-style: normal; text-align: justify; border-collapse: collapse; font-size: 12px; ">3.选择"开始-&gt;运行"，输入"cmd"，在DOS窗口内输入&#8220;mongod -port 27017 -dbpath D:/deployment/mongoDb/data/db -logpath D:/deployment/mongoDb/data/log/logs.log &#8221;，其中dbpath 为数据文件存储路径，logpath&nbsp;为日志文件存储路径。</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-weight: normal; font-style: normal; text-align: justify; border-collapse: collapse; font-size: 12px; ">4.不要关闭上面的窗口，新打开一个DOS，输入&#8220;mongo-&gt;use admin-&gt;db.AddUser(username,password)&#8221;,username:数据库数据集的用户名，password数据库数据集操作的密码。</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-weight: normal; font-style: normal; text-align: justify; border-collapse: collapse; font-size: 12px; ">5.在两个DOS窗口内分别按&#8220;ctrl+c&#8221;，在第一个DOS窗口内输入&#8220;mongod -port 27017 -dbpath D:/deployment/mongoDb/data/db -logpath D:/deployment/mongoDb/data/log/logs.log -logappend -auth&#8221;的启动命令，auth是要求操作数据集是需要验证。</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-weight: normal; font-style: normal; text-align: justify; border-collapse: collapse; font-size: 12px; ">6.在第二个DOS窗口内，输入&#8220;mongo-&gt;use admin-&gt;db.auth(username,password)&#8221;，然后就可以对数据集进行操作（增、删、改）。</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-weight: normal; font-style: normal; text-align: justify; border-collapse: collapse; font-size: 12px; "><br />
</p>
<p style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-weight: normal; font-style: normal; text-align: justify; border-collapse: collapse; font-size: 12px; ">来自:<span  style="border-collapse: separate; font-size: medium; "><a href="http://www.hitb.com.cn/web/guest/bbs/-/message_boards/message/26944">http://www.hitb.com.cn/web/guest/bbs/-/message_boards/message/26944</a></span></p>
<img src ="http://www.blogjava.net/waterjava/aggbug/346832.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/waterjava/" target="_blank">狼爱上狸</a> 2011-03-23 11:00 <a href="http://www.blogjava.net/waterjava/archive/2011/03/23/346832.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>win7 启动 mongo 方案</title><link>http://www.blogjava.net/waterjava/archive/2011/03/23/346822.html</link><dc:creator>狼爱上狸</dc:creator><author>狼爱上狸</author><pubDate>Wed, 23 Mar 2011 02:32:00 GMT</pubDate><guid>http://www.blogjava.net/waterjava/archive/2011/03/23/346822.html</guid><wfw:comment>http://www.blogjava.net/waterjava/comments/346822.html</wfw:comment><comments>http://www.blogjava.net/waterjava/archive/2011/03/23/346822.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/waterjava/comments/commentRss/346822.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/waterjava/services/trackbacks/346822.html</trackback:ping><description><![CDATA[<a href="http://www.360doc.com/content/10/0618/22/10626_33885376.shtml">http://www.360doc.com/content/10/0618/22/10626_33885376.shtml</a>
<img src ="http://www.blogjava.net/waterjava/aggbug/346822.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/waterjava/" target="_blank">狼爱上狸</a> 2011-03-23 10:32 <a href="http://www.blogjava.net/waterjava/archive/2011/03/23/346822.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mongo 命令集</title><link>http://www.blogjava.net/waterjava/archive/2011/03/23/346820.html</link><dc:creator>狼爱上狸</dc:creator><author>狼爱上狸</author><pubDate>Wed, 23 Mar 2011 02:31:00 GMT</pubDate><guid>http://www.blogjava.net/waterjava/archive/2011/03/23/346820.html</guid><wfw:comment>http://www.blogjava.net/waterjava/comments/346820.html</wfw:comment><comments>http://www.blogjava.net/waterjava/archive/2011/03/23/346820.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/waterjava/comments/commentRss/346820.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/waterjava/services/trackbacks/346820.html</trackback:ping><description><![CDATA[<span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">首先在mongo官网下载Windows的版本</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">启动服务：mongod.exe --port 12345 --dbpath=c:\mongodb\db</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">显示一下信息：</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">Fri Dec 04 14:30:32 Mongo DB : starting : pid = 0 port = 12345 dbpath = c:\mongo</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">db\db master = 0 slave = 0&nbsp; 32-bit</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">**&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; see http://blog.mongodb.org/post/137788967/32-bit-limitations for more</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">Fri Dec 04 14:30:32 db version v1.1.4-, pdfile version 4.5</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">Fri Dec 04 14:30:32 git version: c67c2f7dd681152f1784c8e1c2119b979e65881d</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">Fri Dec 04 14:30:32 sys info: windows (5, 1, 2600, 2, 'Service Pack 3') BOOST_LI</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">B_VERSION=1_35</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">Fri Dec 04 14:30:32 waiting for connections on port 12345</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">启动客户端：mongo.exe localhost:12345</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">检查是否正常:db.foo.save({a:1,b:9})</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp; db.foo.find({a:1})</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">控制台显示：{ "_id" : ObjectId("4b18b5b56f40000000006cec"), "a" : 1, "b" : 9 }</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">添加数据：db.foo.save({a:1,b:9})</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">查询数据：db.foo.find({a:1})&nbsp; //{a:1}是查询条件，当为空时查询所有</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp; db.foo.findOne({a:1}) //显示出一条数据</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">删除数据：db.foo.remove({a:1}) //删除a=1的数据</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">表的数据量:db.foo.find().count()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">显示数据指定的条数:db.foo.find().limit(n)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">显示库名:db.foo.getDB()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">获取索引值：db.foo.getIndexes()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">表的统计:db.foo.stats()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">删除表:db.foo.drop()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">获取不重复的列：db.foo.distinct( key ) - eg. db.foo.distinct( 'x' )</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">忽略前面的几行：db.other.find({a:2}).skip(2)//忽略a=2中的前面2行</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">方法帮助:db.foo.help()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">HELP</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; show dbs&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; show database names</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; show collections&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; show collections in current database</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; show users&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; show users in current database</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; show profile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; show most recent system.profile entries with time &gt;= 1ms</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; use &lt;db name&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set curent database to &lt;db name&gt;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.help()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; help on DB methods</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.help()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; help on collection methods</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.find()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list objects in collection foo</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.find( { a : 1 } )&nbsp;&nbsp;&nbsp;&nbsp; list objects in foo where a == 1</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; it&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result of the last line evaluated; use to further iterate</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">DB methods:</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.addUser(username, password)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.auth(username, password)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.cloneDatabase(fromhost)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.commandHelp(name) returns the help for the command</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.copyDatabase(fromdb, todb, fromhost)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.createCollection(name, { size : ..., capped : ..., max : ... } )</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.currentOp() displays the current operation in the db</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.dropDatabase()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.eval(func, args) run code server-side</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getCollection(cname) same as db['cname'] or db.cname</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getCollectionNames()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getLastError() - just returns the err msg string</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getLastErrorObj() - return full status object</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getMongo() get the server connection object</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getMongo().setSlaveOk() allow this connection to read from the nonmaster member of a replica pair</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getName()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getPrevError()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getProfilingLevel()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getReplicationInfo()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getSisterDB(name) get the db at the same server as this onew</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.killOp() kills the current operation in the db</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.printCollectionStats()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.printReplicationInfo()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.printSlaveReplicationInfo()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.printShardingStatus()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.removeUser(username)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.repairDatabase()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.resetError()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.runCommand(cmdObj) run a database command.&nbsp; if cmdObj is a string, turns it into { cmdObj : 1 }</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.setProfilingLevel(level) 0=off 1=slow 2=all</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.shutdownServer()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.version() current version of the server</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">DBCollection help</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.count()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.dataSize()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.distinct( key ) - eg. db.foo.distinct( 'x' )</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.drop() drop the collection</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.dropIndex(name)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.dropIndexes()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.ensureIndex(keypattern,options) - options should be an object with these possible fields: name, unique, dropDups</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.find( [query] , [fields]) - first parameter is an optional queryfilter. second parameter is optional set of fields to return.&nbsp; e.g. db.foo.find( { x : 77 } , { name : 1 , x : 1 } )</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.find(...).count()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.find(...).limit(n)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.find(...).skip(n)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.find(...).sort(...)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.findOne([query])</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.getDB() get DB object associated with collection</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.getIndexes()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.mapReduce( mapFunction , reduceFunction , &lt;optional params&gt; )</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.remove(query)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.renameCollection( newName ) renames the collection</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.save(obj)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.stats()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.storageSize() - includes free space allocated to this collection</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.totalIndexSize() - size in bytes of all the indexes</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.totalSize() - storage allocated for all data and indexes</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.update(query, object[, upsert_bool])</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.validate() - SLOW</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.getShardVersion() - only for use with sharding</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span>
<div><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span></div>
<div><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">来自:&nbsp;</span><a href="http://canofy.javaeye.com/blog/540926">http://canofy.javaeye.com/blog/540926</a></div>
<img src ="http://www.blogjava.net/waterjava/aggbug/346820.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/waterjava/" target="_blank">狼爱上狸</a> 2011-03-23 10:31 <a href="http://www.blogjava.net/waterjava/archive/2011/03/23/346820.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mongo shell命令</title><link>http://www.blogjava.net/waterjava/archive/2011/03/23/346819.html</link><dc:creator>狼爱上狸</dc:creator><author>狼爱上狸</author><pubDate>Wed, 23 Mar 2011 02:29:00 GMT</pubDate><guid>http://www.blogjava.net/waterjava/archive/2011/03/23/346819.html</guid><wfw:comment>http://www.blogjava.net/waterjava/comments/346819.html</wfw:comment><comments>http://www.blogjava.net/waterjava/archive/2011/03/23/346819.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/waterjava/comments/commentRss/346819.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/waterjava/services/trackbacks/346819.html</trackback:ping><description><![CDATA[<h3 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">命令行</h3>
<div class="table-wrap" style="font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">
<table class="confluenceTable" border="0">
    <tbody>
        <tr>
            <td class="confluenceTd"><tt>--help</tt></td>
            <td class="confluenceTd">显示命令行参数</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>--nodb</tt></td>
            <td class="confluenceTd">不连接数据库方式启动，稍后可以使用&nbsp;<tt>new Mongo()</tt>&nbsp;或&nbsp;<tt>connect()</tt>&nbsp;来建立连接</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>--shell</tt></td>
            <td class="confluenceTd">从命令行运行完一个 .js 文件后，停留在shell中，而不是结束</td>
        </tr>
    </tbody>
</table>
</div>
<h3 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; "><a name="Shell参考-特殊命令" style="text-decoration: none; color: #336699; width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat; "></a>特殊命令</h3>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">非JavaScript的辅助指令：</p>
<div class="table-wrap" style="font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">
<table class="confluenceTable" border="0">
    <tbody>
        <tr>
            <td class="confluenceTd"><tt>help</tt></td>
            <td class="confluenceTd">显示帮助</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>db.help()</tt></td>
            <td class="confluenceTd">显示 db 方法帮助</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>db.<em style="font-style: italic; ">myColl</em>&nbsp;.help()</tt></td>
            <td class="confluenceTd">显示聚集的方法帮助</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>show dbs</tt></td>
            <td class="confluenceTd">打印服务器上所有数据库的列表</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>use&nbsp;<em style="font-style: italic; ">dbname</em></tt></td>
            <td class="confluenceTd">设置db变量来指明使用服务器上的&nbsp;<em style="font-style: italic; ">dbname</em>&nbsp;数据库</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>show collections</tt></td>
            <td class="confluenceTd">打印当前数据库的所有聚集</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>show users</tt></td>
            <td class="confluenceTd">打印当前数据库的用户</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>show profile</tt></td>
            <td class="confluenceTd">打印最近耗时大于1ms的profiling操作</td>
        </tr>
    </tbody>
</table>
</div>
<h3 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; "><a name="Shell参考-基本的ShellJavascript操作" style="text-decoration: none; color: #336699; width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat; "></a>基本的Shell Javascript操作</h3>
<div class="table-wrap" style="font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">
<table class="confluenceTable" border="0">
    <tbody>
        <tr>
            <td class="confluenceTd"><tt>db</tt></td>
            <td class="confluenceTd">指向当前数据库对象和连接的变量，已经在你的实例里定义好。</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>db.auth(user,pass)</tt></td>
            <td class="confluenceTd">数据库认证（如果运行安全模式的话）</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>coll = db.<em style="font-style: italic; ">collection</em></tt></td>
            <td class="confluenceTd">访问数据库里特定的&nbsp;<em style="font-style: italic; ">collection</em></td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>cursor = coll.find()</tt></td>
            <td class="confluenceTd">查找聚集里所有的对象。参考&nbsp;<span class="error">[查询]</span>&nbsp;。</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>coll.remove(<em style="font-style: italic; ">objpattern</em>&nbsp;)</tt></td>
            <td class="confluenceTd">从聚集里删除匹配的对象。&nbsp;<br class="atl-forced-newline" />
            <tt><em style="font-style: italic; ">objpattern</em>&nbsp;</tt>是一个指定匹配的域的对象，例如：<tt>coll.remove( { name: "Joe" } );</tt></td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>coll.save(<em style="font-style: italic; ">object</em>&nbsp;)</tt></td>
            <td class="confluenceTd">在聚集中保存对象，如果已经存在的话则更新它。&nbsp;<br class="atl-forced-newline" />
            如果对象有 presave 方法，则会在保存到数据库之前（插入和更新之前）调用该方法。</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>coll.insert(object)</tt></td>
            <td class="confluenceTd">向聚集中插入对象。不会检查该对象是否已经存在聚集中（即，不是 upsert）</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>coll.update(...)</tt></td>
            <td class="confluenceTd">在聚集中更新对象。update() 有许多参数，请查看&nbsp;<a title="更新" href="http://www.mongodb.org/pages/viewpage.action?pageId=20742684" style="text-decoration: none; color: #336699; ">更新</a>&nbsp;文档。</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>coll.ensureIndex( {&nbsp;<em style="font-style: italic; ">name</em>&nbsp;: 1 } )</tt></td>
            <td class="confluenceTd">对&nbsp;<tt><em style="font-style: italic; ">name</em>&nbsp;</tt>建索引。如果索引存在则不做任何事。</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>coll.drop()</tt></td>
            <td class="confluenceTd">删除&nbsp;<tt>coll</tt>&nbsp;聚集</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>db.getSisterDB(name)</tt></td>
            <td class="confluenceTd">返回当前连接的另一个数据库。它允许跨数据库查询，例如：<tt>db.getSisterDB('production').getCollectionNames()</tt></td>
        </tr>
    </tbody>
</table>
</div>
<h3 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; "><a name="Shell参考-查询" style="text-decoration: none; color: #336699; width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat; "></a>查询</h3>
<div class="table-wrap" style="font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">
<table class="confluenceTable" border="0">
    <tbody>
        <tr>
            <td class="confluenceTd"><tt>coll.find()</tt></td>
            <td class="confluenceTd">查询所有文档</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>it</tt></td>
            <td class="confluenceTd">循环上次 find() 调用返回的游标</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>coll.find(&nbsp;<em style="font-style: italic; ">criteria</em>&nbsp;);</tt></td>
            <td class="confluenceTd">查询聚集中匹配&nbsp;<tt><em style="font-style: italic; ">criteria</em>&nbsp;</tt>的对象。例如：<tt>coll.find( { name: "Joe" } );</tt></td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>coll.findOne(&nbsp;<em style="font-style: italic; ">criteria</em>);</tt></td>
            <td class="confluenceTd">查询并返回一个对象。如果没有找到则返回 null。如果你只需要返回一个对象，这个方法比&nbsp;<tt>find()</tt>&nbsp;as&nbsp;<tt>limit(1)</tt>&nbsp;效率更高。如果元素类型是字符串，数字或时间，你还可以使用正则表达式：<tt>coll.find( { name: /joe/i } );</tt></td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>coll.find( criteria, fields );</tt></td>
            <td class="confluenceTd">查询对象里特定的域。例如：<tt>coll.find( {}, {name:true} );</tt></td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>coll.find().sort( {<em style="font-style: italic; ">field</em>&nbsp;:1[,&nbsp;<em style="font-style: italic; ">field</em>&nbsp;:1] });</tt></td>
            <td class="confluenceTd">对返回结果进行排序（field ASC）。使用 -1 表示 DESC。</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>coll.find(&nbsp;<em style="font-style: italic; ">criteria</em>&nbsp;).sort( {&nbsp;<em style="font-style: italic; ">field</em>&nbsp;: 1 } )</tt></td>
            <td class="confluenceTd">查找匹配&nbsp;<tt><em style="font-style: italic; ">criteria</em>&nbsp;</tt>的对象，并对&nbsp;<tt><em style="font-style: italic; ">field</em>&nbsp;</tt>进行排序。</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>coll.find( ... ).limit(<em style="font-style: italic; ">n</em>&nbsp;)</tt></td>
            <td class="confluenceTd">限制结果返回&nbsp;<tt><em style="font-style: italic; ">n</em>&nbsp;</tt>行。如果你只需要某几行数据，推荐这样做来获得最优性能。</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>coll.find( ... ).skip(<em style="font-style: italic; ">n</em>)</tt></td>
            <td class="confluenceTd">跳过&nbsp;<tt><em style="font-style: italic; ">n</em>&nbsp;</tt>行结果。</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>coll.count()</tt></td>
            <td class="confluenceTd">返回聚集里对象的总数。</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>coll.find( ... ).count()</tt></td>
            <td class="confluenceTd">返回匹配该查询的对象总数。注意，该返回会忽略 limit 和 skip。比如有100行记录匹配该查询，但是limit为10，<tt>count()</tt>&nbsp;仍会返回100。这比你自己循环更快，但仍然需要消耗些时间。</td>
        </tr>
    </tbody>
</table>
</div>
<p style="padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; margin-top: 1em; margin-right: 0px; margin-bottom: 0.5em; margin-left: 0px; font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">更多信息请参考&nbsp;<span class="error" style="line-height: 21px; ">[查询]</span>&nbsp;。</p>
<h3 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; "><a name="Shell参考-错误检查" style="text-decoration: none; color: #336699; width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat; "></a>错误检查</h3>
<div class="table-wrap" style="font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">
<table class="confluenceTable" border="0">
    <tbody>
        <tr>
            <td class="confluenceTd"><span class="error">[{{db.getLastError()}}]</span></td>
            <td class="confluenceTd">返回上次操作的错误</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>db.getPrevError()</tt></td>
            <td class="confluenceTd">返回之前操作的错误</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>db.resetError()</tt></td>
            <td class="confluenceTd">清除错误记录</td>
        </tr>
    </tbody>
</table>
</div>
<h3 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; "><a name="Shell参考-管理命令" style="text-decoration: none; color: #336699; width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat; "></a>管理命令</h3>
<div class="table-wrap" style="font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">
<table class="confluenceTable" border="0">
    <tbody>
        <tr>
            <td class="confluenceTd"><tt>db.cloneDatabase(fromhost)</tt></td>
            <td class="confluenceTd">从另外指定的主机拷贝当前数据数据库。fromhost必须为noauth模式。</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>db.copyDatabase(fromdb, todb, fromhost)</tt></td>
            <td class="confluenceTd">拷贝fromhost的fromdb数据库到当前服务器的todb数据库。fromhost必须为noauth模式。</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>db.repairDatabase()</tt></td>
            <td class="confluenceTd">修复当前数据库。如果数据库很大则该操作会非常慢。</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>db.addUser(user,pwd)</tt></td>
            <td class="confluenceTd">给当前数据库添加用户。</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>db.getCollectionNames()</tt></td>
            <td class="confluenceTd">获得所有聚集的列表。</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>db.dropDatabase()</tt></td>
            <td class="confluenceTd">删除当前数据库。</td>
        </tr>
    </tbody>
</table>
</div>
<h3 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; "><a name="Shell参考-打开额外连接" style="text-decoration: none; color: #336699; width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat; "></a>打开额外连接</h3>
<div class="table-wrap" style="font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">
<table class="confluenceTable" border="0">
    <tbody>
        <tr>
            <td class="confluenceTd"><tt>db = connect("&lt;host&gt;:&lt;port&gt;/&lt;dbname&gt;")</tt></td>
            <td class="confluenceTd">打开一个新的数据库连接。一个shell可能有多个连接，但是shell自动的getLastError只用于 'db' 变量。</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>conn = new Mongo("hostname")</tt></td>
            <td class="confluenceTd">打开一个新的服务器连接。然后可以使用&nbsp;<tt>getDB()</tt>&nbsp;来选择一个数据库。</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>db = conn.getDB("dbname")</tt></td>
            <td class="confluenceTd">对一个连接选择一个特定的数据库。</td>
        </tr>
    </tbody>
</table>
</div>
<h3 style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; "><a name="Shell参考-其他" style="text-decoration: none; color: #336699; width: 20px; height: 20px; text-indent: 20px; background-image: url(http://www.blogjava.net/CuteSoft_Client/CuteEditor/Load.ashx?type=image&amp;file=anchor.gif); background-repeat: no-repeat no-repeat; "></a>其他</h3>
<div class="table-wrap" style="font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">
<table class="confluenceTable" border="0">
    <tbody>
        <tr>
            <td class="confluenceTd"><tt>Object.bsonsize(db.foo.findOne())</tt></td>
            <td class="confluenceTd">打印一个数据库对象的bson大小（mongo 版本1.3及以上）</td>
        </tr>
        <tr>
            <td class="confluenceTd"><tt>db.foo.findOne().bsonsize()</tt></td>
            <td class="confluenceTd">打印一个数据库对象的bson大小 (mongo 版本1.3之前)</td>
        </tr>
    </tbody>
</table>
<br />
</div>
<div class="table-wrap" style="font-family: verdana, sans-serif; font-size: 14px; line-height: 21px; ">来自:<span  style="font-family: Simsun; line-height: normal; font-size: medium; "><a href="http://blog.csdn.net/zxkln/archive/2011/01/04/6114793.aspx">http://blog.csdn.net/zxkln/archive/2011/01/04/6114793.aspx</a></span></div>
<img src ="http://www.blogjava.net/waterjava/aggbug/346819.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/waterjava/" target="_blank">狼爱上狸</a> 2011-03-23 10:29 <a href="http://www.blogjava.net/waterjava/archive/2011/03/23/346819.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mongo phpadmin客户端</title><link>http://www.blogjava.net/waterjava/archive/2011/03/23/346817.html</link><dc:creator>狼爱上狸</dc:creator><author>狼爱上狸</author><pubDate>Wed, 23 Mar 2011 02:28:00 GMT</pubDate><guid>http://www.blogjava.net/waterjava/archive/2011/03/23/346817.html</guid><wfw:comment>http://www.blogjava.net/waterjava/comments/346817.html</wfw:comment><comments>http://www.blogjava.net/waterjava/archive/2011/03/23/346817.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/waterjava/comments/commentRss/346817.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/waterjava/services/trackbacks/346817.html</trackback:ping><description><![CDATA[<span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">其实用mongo已经有些时候了，之所以算初探，是因为用的不深入，主要就是当中nosql中的类k-v用的，用之取代了部分的tt，原因很简单，mongo中的数据格式虽然是bson的，不过在我这个pythoner眼中，这不明明就是纯天然的 dict么！好吧，我承认，就是这个原因让我义无反顾地走上了mongoing之路(无论什么项目，用到存储自然而然的想用mongo)。</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">mongo的优劣是在使用的过程中逐步体验出来的，在这里就不评说了，想要评测的请直接google之</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><img src="http://iyuan.javaeye.com/images/smiles/icon_wink.gif" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "  alt="" /></span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">之前一直是直接在服务器端用pymongo或者mongo自带的shell做数据查看修改之类的操作，突然发现这个实在不利于推广，公司同事似乎本能的对这种nosql有稳定性上的怀疑。也好理解，看不到的，通常是不可信的(谁说的来着)。</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">鉴于大伙都习惯了phpadmin玩mysql的光荣传统，如果mongo也有类似的东东，看起来也亲切些，个人感觉对推广也会有利些。</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">额，说了这么多，好像还没有能进入到主题，好吧，说是初探，似乎有些标题党了，其实就想推荐下这个东东：</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><a href="http://code.google.com/p/rock-php/wiki/rock_mongo_zh#安装" target="_blank" style="color: #108ac6; text-decoration: underline; ">http://code.google.com/p/rock-php/wiki/rock_mongo_zh#安装</a></span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">不错的mongodb phpadmin客户端，还支持中文(我想这个还是蛮有利推广的)，所谓初探，只不过是使用这东东换了个视角来看看Mongodb,感觉的确有些不一样。</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">不过，值得注意到是，装这玩意之前，还得为php装一个mongo的drive，不过不要紧，装完这个之后，访问时会直接给个装drive的链接，还是蛮方便的。</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">额，我应该不算标题党吧（至少不是纯碎的标题党。。</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><img src="http://iyuan.javaeye.com/images/smiles/icon_biggrin.gif" style="border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; "  alt="" /></span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">）</span>
<div><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">来自:</span><a href="http://iyuan.javaeye.com/blog/799515">http://iyuan.javaeye.com/blog/799515</a></div>
<img src ="http://www.blogjava.net/waterjava/aggbug/346817.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/waterjava/" target="_blank">狼爱上狸</a> 2011-03-23 10:28 <a href="http://www.blogjava.net/waterjava/archive/2011/03/23/346817.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mongo常用操作</title><link>http://www.blogjava.net/waterjava/archive/2011/03/23/346816.html</link><dc:creator>狼爱上狸</dc:creator><author>狼爱上狸</author><pubDate>Wed, 23 Mar 2011 02:26:00 GMT</pubDate><guid>http://www.blogjava.net/waterjava/archive/2011/03/23/346816.html</guid><wfw:comment>http://www.blogjava.net/waterjava/comments/346816.html</wfw:comment><comments>http://www.blogjava.net/waterjava/archive/2011/03/23/346816.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/waterjava/comments/commentRss/346816.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/waterjava/services/trackbacks/346816.html</trackback:ping><description><![CDATA[<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">shell#查询<br style="line-height: normal; " />
查询 name = "bruce" 的数据<br style="line-height: normal; " />
db.users.find({ name : "bruce" });</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">条件操作符<br style="line-height: normal; " />
$gt : &gt;<br style="line-height: normal; " />
$lt : &lt;<br style="line-height: normal; " />
$gte: &gt;=<br style="line-height: normal; " />
$lte: &lt;=<br style="line-height: normal; " />
$ne : !=、&lt;&gt;<br style="line-height: normal; " />
$in : in<br style="line-height: normal; " />
$nin: not in<br style="line-height: normal; " />
$all: all<br style="line-height: normal; " />
$not: 反匹配(1.3.3及以上版本)</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">查询 name &lt;&gt; "bruce" and age &gt;= 18 的数据<br style="line-height: normal; " />
db.users.find({name: {$ne: "bruce"}, age: {$gte: 18}});</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">查询 creation_date &gt; '2010-01-01' and creation_date &lt;= '2010-12-31' 的数据<br style="line-height: normal; " />
db.users.find({creation_date:{$gt:new Date(2010,0,1), $lte:new Date(2010,11,31)});</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">查询 age in (20,22,24,26) 的数据<br style="line-height: normal; " />
db.users.find({age: {$in: [20,22,24,26]}});</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">查询 age取模10等于0 的数据<br style="line-height: normal; " />
db.users.find('this.age % 10 == 0');<br style="line-height: normal; " />
或者<br style="line-height: normal; " />
db.users.find({age : {$mod : [10, 0]}});</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">匹配所有<br style="line-height: normal; " />
db.users.find({favorite_number : {$all : [6, 8]}});<br style="line-height: normal; " />
可以查询出{name: 'David', age: 26, favorite_number: [ 6, 8, 9 ] }<br style="line-height: normal; " />
可以不查询出{name: 'David', age: 26, favorite_number: [ 6, 7, 9 ] }</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">查询不匹配name=B*带头的记录<br style="line-height: normal; " />
db.users.find({name: {$not: /^B.*/}});<br style="line-height: normal; " />
查询 age取模10不等于0 的数据<br style="line-height: normal; " />
db.users.find({age : {$not: {$mod : [10, 0]}}});</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">#返回部分字段<br style="line-height: normal; " />
选择返回age和_id字段(_id字段总是会被返回)<br style="line-height: normal; " />
db.users.find({}, {age:1});<br style="line-height: normal; " />
db.users.find({}, {age:3});<br style="line-height: normal; " />
db.users.find({}, {age:true});<br style="line-height: normal; " />
db.users.find({ name : "bruce" }, {age:1});<br style="line-height: normal; " />
0为false, 非0为true</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">选择返回age、address和_id字段<br style="line-height: normal; " />
db.users.find({ name : "bruce" }, {age:1, address:1});</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">排除返回age、address和_id字段<br style="line-height: normal; " />
db.users.find({}, {age:0, address:false});<br style="line-height: normal; " />
db.users.find({ name : "bruce" }, {age:0, address:false});</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">数组元素个数判断<br style="line-height: normal; " />
对于{name: 'David', age: 26, favorite_number: [ 6, 7, 9 ] }记录<br style="line-height: normal; " />
匹配db.users.find({favorite_number: {$size: 3}});<br style="line-height: normal; " />
不匹配db.users.find({favorite_number: {$size: 2}});</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">$exists判断字段是否存在<br style="line-height: normal; " />
查询所有存在name字段的记录<br style="line-height: normal; " />
db.users.find({name: {$exists: true}});<br style="line-height: normal; " />
查询所有不存在phone字段的记录<br style="line-height: normal; " />
db.users.find({phone: {$exists: false}});</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">$type判断字段类型<br style="line-height: normal; " />
查询所有name字段是字符类型的<br style="line-height: normal; " />
db.users.find({name: {$type: 2}});<br style="line-height: normal; " />
查询所有age字段是整型的<br style="line-height: normal; " />
db.users.find({age: {$type: 16}});</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">对于字符字段，可以使用正则表达式<br style="line-height: normal; " />
查询以字母b或者B带头的所有记录<br style="line-height: normal; " />
db.users.find({name: /^b.*/i});</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">$elemMatch(1.3.1及以上版本)<br style="line-height: normal; " />
为数组的字段中匹配其中某个元素</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">Javascript查询和$where查询<br style="line-height: normal; " />
查询 age &gt; 18 的记录，以下查询都一样<br style="line-height: normal; " />
db.users.find({age: {$gt: 18}});<br style="line-height: normal; " />
db.users.find({$where: "this.age &gt; 18"});<br style="line-height: normal; " />
db.users.find("this.age &gt; 18");<br style="line-height: normal; " />
f = function() {return this.age &gt; 18} db.users.find(f);</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">排序sort()<br style="line-height: normal; " />
以年龄升序asc<br style="line-height: normal; " />
db.users.find().sort({age: 1});<br style="line-height: normal; " />
以年龄降序desc<br style="line-height: normal; " />
db.users.find().sort({age: -1});</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">限制返回记录数量limit()<br style="line-height: normal; " />
返回5条记录<br style="line-height: normal; " />
db.users.find().limit(5);<br style="line-height: normal; " />
返回3条记录并打印信息<br style="line-height: normal; " />
db.users.find().limit(3).forEach(function(user) {print('my age is ' + user.age)});<br style="line-height: normal; " />
结果<br style="line-height: normal; " />
my age is 18<br style="line-height: normal; " />
my age is 19<br style="line-height: normal; " />
my age is 20</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">限制返回记录的开始点skip()<br style="line-height: normal; " />
从第3条记录开始，返回5条记录(limit 3, 5)<br style="line-height: normal; " />
db.users.find().skip(3).limit(5);</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">查询记录条数count()<br style="line-height: normal; " />
db.users.find().count();<br style="line-height: normal; " />
db.users.find({age:18}).count();<br style="line-height: normal; " />
以下返回的不是5，而是user表中所有的记录数量<br style="line-height: normal; " />
db.users.find().skip(10).limit(5).count();<br style="line-height: normal; " />
如果要返回限制之后的记录数量，要使用count(true)或者count(非0)<br style="line-height: normal; " />
db.users.find().skip(10).limit(5).count(true);</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">分组group()<br style="line-height: normal; " />
假设test表只有以下一条数据<br style="line-height: normal; " />
{ domain: "<a href="http://www.mongodb.org/" style="color: #6a8400; font-size: 12px; font-family: Verdana, Arial, Helvetica, sans-serif; font-weight: normal; text-decoration: none; line-height: normal; ">www.mongodb.org</a>"<br style="line-height: normal; " />
, invoked_at: {d:"2009-11-03", t:"17:14:05"}<br style="line-height: normal; " />
, response_time: 0.05<br style="line-height: normal; " />
, http_action: "GET /display/DOCS/Aggregation"<br style="line-height: normal; " />
}<br style="line-height: normal; " />
使用group统计test表11月份的数据count:count(*)、total_time:sum(response_time)、 avg_time:total_time/count;<br style="line-height: normal; " />
db.test.group(<br style="line-height: normal; " />
&nbsp;&nbsp; { cond: {"invoked_at.d": {$gt: "2009-11", $lt: "2009-12"}}<br style="line-height: normal; " />
&nbsp;&nbsp; , key: {http_action: true}<br style="line-height: normal; " />
&nbsp;&nbsp; , initial: {count: 0, total_time:0}<br style="line-height: normal; " />
&nbsp;&nbsp; , reduce: function(doc, out){ out.count++; out.total_time+=doc.response_time }<br style="line-height: normal; " />
&nbsp;&nbsp; , finalize: function(out){ out.avg_time = out.total_time / out.count }<br style="line-height: normal; " />
&nbsp;&nbsp; } );</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">[<br style="line-height: normal; " />
&nbsp; {<br style="line-height: normal; " />
&nbsp;&nbsp;&nbsp; "http_action" : "GET /display/DOCS/Aggregation",<br style="line-height: normal; " />
&nbsp;&nbsp;&nbsp; "count" : 1,<br style="line-height: normal; " />
&nbsp;&nbsp;&nbsp; "total_time" : 0.05,<br style="line-height: normal; " />
&nbsp;&nbsp;&nbsp; "avg_time" : 0.05<br style="line-height: normal; " />
&nbsp; }<br style="line-height: normal; " />
]</p>
<p style="line-height: normal; color: #666666; font-family: Arial; font-size: 12px; ">来自:&nbsp;<span  style="color: #000000; font-family: Simsun; font-size: medium; "><a href="http://hi.baidu.com/asminfo/blog/item/20301e22dcfcce50ac34de7a.html">http://hi.baidu.com/asminfo/blog/item/20301e22dcfcce50ac34de7a.html</a></span></p>
<img src ="http://www.blogjava.net/waterjava/aggbug/346816.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/waterjava/" target="_blank">狼爱上狸</a> 2011-03-23 10:26 <a href="http://www.blogjava.net/waterjava/archive/2011/03/23/346816.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>grails 升级到1.3.6的乱码解决方法</title><link>http://www.blogjava.net/waterjava/archive/2011/03/23/346815.html</link><dc:creator>狼爱上狸</dc:creator><author>狼爱上狸</author><pubDate>Wed, 23 Mar 2011 02:25:00 GMT</pubDate><guid>http://www.blogjava.net/waterjava/archive/2011/03/23/346815.html</guid><wfw:comment>http://www.blogjava.net/waterjava/comments/346815.html</wfw:comment><comments>http://www.blogjava.net/waterjava/archive/2011/03/23/346815.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/waterjava/comments/commentRss/346815.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/waterjava/services/trackbacks/346815.html</trackback:ping><description><![CDATA[<table style="table-layout: fixed; width: 960px; font-family: Arial; font-size: 12px; line-height: 18px; ">
    <tbody>
        <tr>
            <td style="font-family: Arial; word-wrap: break-word; word-break: break-all; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 12px; line-height: 18px; ">
            <div id="blog_text" class="cnt" style="font-family: Arial; word-wrap: break-word; word-break: normal; visibility: visible !important; zoom: 1 !important; filter: none; font-size: 14px; line-height: 20px; color: #333333; overflow-x: hidden; overflow-y: hidden; position: static; ">
            <p style="line-height: normal; ">原先的grails是1.2.0，从这个版本之后，我试过1.2.1，1.2.2，1.3.0，1.3.1，但都因为程序在运行时会变成乱码，而一直使用着1.2.0。</p>
            <p style="line-height: normal; ">我们的TOMCAT使用的是GBK编码，GRAILS文本都是使用UTF-8编码，所以，这是产生乱码的根本原因。</p>
            <p style="line-height: normal; ">最近又有grails1.3.6，更新得很快，网上找了找，有解决方案了。<a target="_blank" href="http://www.groovyq.net/content/grails13%E5%8F%91%E5%B8%83" style="line-height: normal; ">http://www.groovyq.net/content/grails13%E5%8F%91%E5%B8%83</a></p>
            <p style="line-height: normal; ">在服务器上一试，果然能行。现记录如下：</p>
            <p style="line-height: normal; ">重新设定System.out的编码，将下面语句加入到_GrailsInit.groovy中，或者加入工程的BootStrap.groovy的init段即可<br style="line-height: normal; " />
            System.out = new PrintStream(System.out, true,"GB2312");</p>
            <p style="line-height: normal; ">&nbsp;</p>
            <p style="line-height: normal; ">我使用的是第二种方法，在BootStrap.groovy的init段中加入以上语句。</p>
            <p style="line-height: normal; ">以前，有位高手也提到过，但他的原文是：</p>
            <p style="line-height: normal; ">&#8220;如果是println打印中文乱码的话，那么就在初始化文件中增加<br style="line-height: normal; " />
            &nbsp;System.out = new&nbsp; PrintStream(System.out, true, "GBK")&nbsp;<br style="line-height: normal; " />
            就应该了，你测试一下吧， &#8221;</p>
            <p style="line-height: normal; ">所以我一直以为是解决打印乱码的。</p>
            <p style="line-height: normal; ">在此一并谢过。</p>
            <p style="line-height: normal; "><br />
            </p>
            <p style="line-height: normal; ">来自:&nbsp;<span  style="line-height: 20px; "><a href="http://hi.baidu.com/caihexi/blog/item/76d093a4cce0c6e59152ee15.html">http://hi.baidu.com/caihexi/blog/item/76d093a4cce0c6e59152ee15.html</a></span></p>
            </div>
            </td>
        </tr>
    </tbody>
</table>
<img src ="http://www.blogjava.net/waterjava/aggbug/346815.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/waterjava/" target="_blank">狼爱上狸</a> 2011-03-23 10:25 <a href="http://www.blogjava.net/waterjava/archive/2011/03/23/346815.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MongoDB的基本操作</title><link>http://www.blogjava.net/waterjava/archive/2011/03/23/346814.html</link><dc:creator>狼爱上狸</dc:creator><author>狼爱上狸</author><pubDate>Wed, 23 Mar 2011 02:24:00 GMT</pubDate><guid>http://www.blogjava.net/waterjava/archive/2011/03/23/346814.html</guid><wfw:comment>http://www.blogjava.net/waterjava/comments/346814.html</wfw:comment><comments>http://www.blogjava.net/waterjava/archive/2011/03/23/346814.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/waterjava/comments/commentRss/346814.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/waterjava/services/trackbacks/346814.html</trackback:ping><description><![CDATA[详细请阅:&nbsp;
<div><a href="http://www.oschina.net/code/snippet_35115_2888">http://www.oschina.net/code/snippet_35115_2888</a></div>
<img src ="http://www.blogjava.net/waterjava/aggbug/346814.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/waterjava/" target="_blank">狼爱上狸</a> 2011-03-23 10:24 <a href="http://www.blogjava.net/waterjava/archive/2011/03/23/346814.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MongoDB的自增长主键的实现</title><link>http://www.blogjava.net/waterjava/archive/2011/03/23/346813.html</link><dc:creator>狼爱上狸</dc:creator><author>狼爱上狸</author><pubDate>Wed, 23 Mar 2011 02:23:00 GMT</pubDate><guid>http://www.blogjava.net/waterjava/archive/2011/03/23/346813.html</guid><wfw:comment>http://www.blogjava.net/waterjava/comments/346813.html</wfw:comment><comments>http://www.blogjava.net/waterjava/archive/2011/03/23/346813.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/waterjava/comments/commentRss/346813.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/waterjava/services/trackbacks/346813.html</trackback:ping><description><![CDATA[详细请阅:&nbsp;
<div><a href="http://www.oschina.net/code/snippet_35115_2915">http://www.oschina.net/code/snippet_35115_2915</a></div>
<img src ="http://www.blogjava.net/waterjava/aggbug/346813.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/waterjava/" target="_blank">狼爱上狸</a> 2011-03-23 10:23 <a href="http://www.blogjava.net/waterjava/archive/2011/03/23/346813.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mongo的初体验</title><link>http://www.blogjava.net/waterjava/archive/2011/03/23/346812.html</link><dc:creator>狼爱上狸</dc:creator><author>狼爱上狸</author><pubDate>Wed, 23 Mar 2011 02:22:00 GMT</pubDate><guid>http://www.blogjava.net/waterjava/archive/2011/03/23/346812.html</guid><wfw:comment>http://www.blogjava.net/waterjava/comments/346812.html</wfw:comment><comments>http://www.blogjava.net/waterjava/archive/2011/03/23/346812.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/waterjava/comments/commentRss/346812.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/waterjava/services/trackbacks/346812.html</trackback:ping><description><![CDATA[<span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">首先在mongo官网下载Windows的版本</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">启动服务：mongod.exe --port 12345 --dbpath=c:\mongodb\db</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">显示一下信息：</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">Fri Dec 04 14:30:32 Mongo DB : starting : pid = 0 port = 12345 dbpath = c:\mongo</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">db\db master = 0 slave = 0&nbsp; 32-bit</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">** NOTE: when using MongoDB 32 bit, you are limited to about 2 gigabytes of data</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">**&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; see http://blog.mongodb.org/post/137788967/32-bit-limitations for more</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">Fri Dec 04 14:30:32 db version v1.1.4-, pdfile version 4.5</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">Fri Dec 04 14:30:32 git version: c67c2f7dd681152f1784c8e1c2119b979e65881d</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">Fri Dec 04 14:30:32 sys info: windows (5, 1, 2600, 2, 'Service Pack 3') BOOST_LI</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">B_VERSION=1_35</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">Fri Dec 04 14:30:32 waiting for connections on port 12345</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">启动客户端：mongo.exe localhost:12345</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">检查是否正常:db.foo.save({a:1,b:9})</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp; db.foo.find({a:1})</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">控制台显示：{ "_id" : ObjectId("4b18b5b56f40000000006cec"), "a" : 1, "b" : 9 }</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">添加数据：db.foo.save({a:1,b:9})</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">查询数据：db.foo.find({a:1})&nbsp; //{a:1}是查询条件，当为空时查询所有</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp; db.foo.findOne({a:1}) //显示出一条数据</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">删除数据：db.foo.remove({a:1}) //删除a=1的数据</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">表的数据量:db.foo.find().count()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">显示数据指定的条数:db.foo.find().limit(n)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">显示库名:db.foo.getDB()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">获取索引值：db.foo.getIndexes()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">表的统计:db.foo.stats()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">删除表:db.foo.drop()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">获取不重复的列：db.foo.distinct( key ) - eg. db.foo.distinct( 'x' )</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">忽略前面的几行：db.other.find({a:2}).skip(2)//忽略a=2中的前面2行</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">方法帮助:db.foo.help()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">HELP</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; show dbs&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; show database names</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; show collections&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; show collections in current database</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; show users&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; show users in current database</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; show profile&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; show most recent system.profile entries with time &gt;= 1ms</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; use &lt;db name&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; set curent database to &lt;db name&gt;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.help()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; help on DB methods</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.help()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; help on collection methods</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.find()&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; list objects in collection foo</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.find( { a : 1 } )&nbsp;&nbsp;&nbsp;&nbsp; list objects in foo where a == 1</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; it&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result of the last line evaluated; use to further iterate</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">DB methods:</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.addUser(username, password)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.auth(username, password)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.cloneDatabase(fromhost)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.commandHelp(name) returns the help for the command</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.copyDatabase(fromdb, todb, fromhost)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.createCollection(name, { size : ..., capped : ..., max : ... } )</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.currentOp() displays the current operation in the db</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.dropDatabase()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.eval(func, args) run code server-side</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getCollection(cname) same as db['cname'] or db.cname</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getCollectionNames()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getLastError() - just returns the err msg string</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getLastErrorObj() - return full status object</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getMongo() get the server connection object</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getMongo().setSlaveOk() allow this connection to read from the nonmaster member of a replica pair</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getName()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getPrevError()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getProfilingLevel()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getReplicationInfo()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.getSisterDB(name) get the db at the same server as this onew</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.killOp() kills the current operation in the db</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.printCollectionStats()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.printReplicationInfo()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.printSlaveReplicationInfo()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.printShardingStatus()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.removeUser(username)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.repairDatabase()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.resetError()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.runCommand(cmdObj) run a database command.&nbsp; if cmdObj is a string, turns it into { cmdObj : 1 }</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.setProfilingLevel(level) 0=off 1=slow 2=all</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.shutdownServer()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.version() current version of the server</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">DBCollection help</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.count()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.dataSize()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.distinct( key ) - eg. db.foo.distinct( 'x' )</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.drop() drop the collection</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.dropIndex(name)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.dropIndexes()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.ensureIndex(keypattern,options) - options should be an object with these possible fields: name, unique, dropDups</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.find( [query] , [fields]) - first parameter is an optional queryfilter. second parameter is optional set of fields to return.&nbsp; e.g. db.foo.find( { x : 77 } , { name : 1 , x : 1 } )</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.find(...).count()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.find(...).limit(n)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.find(...).skip(n)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.find(...).sort(...)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.findOne([query])</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.getDB() get DB object associated with collection</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.getIndexes()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.group( { key : ..., initial: ..., reduce : ...[, cond: ...] } )</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.mapReduce( mapFunction , reduceFunction , &lt;optional params&gt; )</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.remove(query)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.renameCollection( newName ) renames the collection</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.save(obj)</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.stats()</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.storageSize() - includes free space allocated to this collection</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.totalIndexSize() - size in bytes of all the indexes</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.totalSize() - storage allocated for all data and indexes</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.update(query, object[, upsert_bool])</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.validate() - SLOW</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; "><br />
</span><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; db.foo.getShardVersion() - only for use with shardin</span>
<div><span  style="font-family: Arial, sans-serif, Helvetica, Tahoma; font-size: 12px; line-height: 18px; ">来自:&nbsp;</span><a href="http://canofy.javaeye.com/blog/540926">http://canofy.javaeye.com/blog/540926</a></div>
<img src ="http://www.blogjava.net/waterjava/aggbug/346812.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/waterjava/" target="_blank">狼爱上狸</a> 2011-03-23 10:22 <a href="http://www.blogjava.net/waterjava/archive/2011/03/23/346812.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>