doc: update mongodb.md (#343)

fix some translation issues e606837a88
This commit is contained in:
jaywcjlove
2023-04-09 13:19:13 +00:00
parent fd04f1b385
commit 67e8b697cd
5 changed files with 46 additions and 44 deletions

View File

@ -33,7 +33,7 @@
<p><a href="https://www.mongodb.com/developer/products/mongodb/cheat-sheet/#connect-mongodb-shell">MongoDB</a> 此备忘单包含一些方便的提示、命令和快速参考,可让您立即连接并进行 CRUD</p>
</div></header><div class="menu-tocs"><div class="menu-btn"><svg aria-hidden="true" fill="currentColor" height="1em" width="1em" viewBox="0 0 16 16" version="1.1" data-view-component="true">
<path fill-rule="evenodd" d="M2 4a1 1 0 100-2 1 1 0 000 2zm3.75-1.5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zM3 8a1 1 0 11-2 0 1 1 0 012 0zm-1 6a1 1 0 100-2 1 1 0 000 2z"></path>
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#入门">入门</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#连接-mongodb-shell">连接 MongoDB Shell</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#显示数据库">显示数据库</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#切换数据库">切换数据库</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#显示收藏">显示收藏</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#运行-javascript-文件">运行 JavaScript 文件</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#crud">CRUD</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#创建">创建</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#寻找文件">寻找文件</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#使用运算符查找文档">使用运算符查找文档</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#读取">读取</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#更新">更新</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#删除">删除</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#数据库和集合">数据库和集合</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#drop">Drop</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#创建集合">创建集合</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#其他采集功能">其他采集功能</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#索引">索引</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#列表索引">列表索引</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#创建索引">创建索引</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#删除索引">删除索引</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#隐藏取消隐藏索引">隐藏/取消隐藏索引</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#方便的命令">方便的命令</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#"> </a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#各种各样的">各种各样的</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#改变流">改变流</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#分片集群">分片集群</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#副本集">副本集</a></div></div><div class="h1wrap-body"><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="入门"><a aria-hidden="true" tabindex="-1" href="#入门"><span class="icon icon-link"></span></a>入门</h2><div class="wrap-body">
</svg></div><div class="menu-modal"><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#入门">入门</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#连接-mongodb-shell">连接 MongoDB Shell</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#显示数据库">显示数据库</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#切换数据库">切换数据库</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#显示集合">显示集合</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#运行-javascript-文件">运行 JavaScript 文件</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#crud">CRUD</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#创建">创建</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#寻找文件">寻找文件</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#使用运算符查找文档">使用运算符查找文档</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#读取">读取</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#更新">更新</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#删除">删除</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#数据库和集合">数据库和集合</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#drop">Drop</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#创建集合">创建集合</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#其他采集功能">其他采集功能</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#索引">索引</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#列表索引">列表索引</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#创建索引">创建索引</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#删除索引">删除索引</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#隐藏取消隐藏索引">隐藏/取消隐藏索引</a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#方便的命令">方便的命令</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#"> </a><a aria-hidden="true" class="leve2 tocs-link" data-num="2" href="#各种各样的">各种各样的</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#改变流">改变流</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#分片集群">分片集群</a><a aria-hidden="true" class="leve3 tocs-link" data-num="3" href="#副本集">副本集</a></div></div><div class="h1wrap-body"><div class="wrap h2body-exist"><div class="wrap-header h2wrap"><h2 id="入门"><a aria-hidden="true" tabindex="-1" href="#入门"><span class="icon icon-link"></span></a>入门</h2><div class="wrap-body">
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist col-span-2"><div class="wrap-header h3wrap"><h3 id="连接-mongodb-shell"><a aria-hidden="true" tabindex="-1" href="#连接-mongodb-shell"><span class="icon icon-link"></span></a>连接 MongoDB Shell</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-2-->
<pre class="language-bash"><code class="language-bash code-highlight"><span class="code-line">mongo <span class="token comment"># 默认连接到 mongodb://127.0.0.1:27017</span>
@ -49,7 +49,7 @@
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="切换数据库"><a aria-hidden="true" tabindex="-1" href="#切换数据库"><span class="icon icon-link"></span></a>切换数据库</h3><div class="wrap-body">
<pre class="language-mongodb"><code class="language-mongodb code-highlight"><span class="code-line">use <span class="token operator">&#x3C;</span>database_name<span class="token operator">></span>
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="显示收藏"><a aria-hidden="true" tabindex="-1" href="#显示收藏"><span class="icon icon-link"></span></a>显示收藏</h3><div class="wrap-body">
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="显示集合"><a aria-hidden="true" tabindex="-1" href="#显示集合"><span class="icon icon-link"></span></a>显示集合</h3><div class="wrap-body">
<pre class="language-mongodb"><code class="language-mongodb code-highlight"><span class="code-line">show collections
</span></code></pre>
</div></div></div><div class="wrap h3body-not-exist"><div class="wrap-header h3wrap"><h3 id="运行-javascript-文件"><a aria-hidden="true" tabindex="-1" href="#运行-javascript-文件"><span class="icon icon-link"></span></a>运行 JavaScript 文件</h3><div class="wrap-body">
@ -59,7 +59,7 @@
</div></div><div class="h2wrap-body"><div class="wrap h3body-not-exist col-span-3"><div class="wrap-header h3wrap"><h3 id="创建"><a aria-hidden="true" tabindex="-1" href="#创建"><span class="icon icon-link"></span></a>创建</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-3-->
<pre class="language-mongodb"><code class="language-mongodb code-highlight"><span class="code-line">db<span class="token punctuation">.</span><span class="token property-access">coll</span><span class="token punctuation">.</span><span class="token method function property-access">insertOne</span><span class="token punctuation">(</span><span class="token punctuation">{</span> <span class="token property">name</span><span class="token operator">:</span> <span class="token string">"Max"</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
</span><span class="code-line">db<span class="token punctuation">.</span><span class="token property-access">coll</span><span class="token punctuation">.</span><span class="token method function property-access">insert</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">{</span> <span class="token property">name</span><span class="token operator">:</span> <span class="token string">"Max"</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token property">name</span><span class="token operator">:</span><span class="token string">"Alex"</span><span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token comment">// 订购批量插入</span>
</span><span class="code-line">db<span class="token punctuation">.</span><span class="token property-access">coll</span><span class="token punctuation">.</span><span class="token method function property-access">insert</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">{</span> <span class="token property">name</span><span class="token operator">:</span> <span class="token string">"Max"</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token property">name</span><span class="token operator">:</span><span class="token string">"Alex"</span><span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">)</span> <span class="token comment">// 批量插入</span>
</span><span class="code-line">db<span class="token punctuation">.</span><span class="token property-access">coll</span><span class="token punctuation">.</span><span class="token method function property-access">insert</span><span class="token punctuation">(</span><span class="token punctuation">[</span><span class="token punctuation">{</span> <span class="token property">name</span><span class="token operator">:</span> <span class="token string">"Max"</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token property">name</span><span class="token operator">:</span><span class="token string">"Alex"</span><span class="token punctuation">}</span><span class="token punctuation">]</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token property">ordered</span><span class="token operator">:</span> <span class="token boolean">false</span><span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token comment">// 无序批量插入</span>
</span><span class="code-line">db<span class="token punctuation">.</span><span class="token property-access">coll</span><span class="token punctuation">.</span><span class="token method function property-access">insert</span><span class="token punctuation">(</span><span class="token punctuation">{</span> <span class="token property">date</span><span class="token operator">:</span> <span class="token builtin keyword">ISODate</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
</span><span class="code-line">db<span class="token punctuation">.</span><span class="token property-access">coll</span><span class="token punctuation">.</span><span class="token method function property-access">insert</span><span class="token punctuation">(</span><span class="token punctuation">{</span> <span class="token property">name</span><span class="token operator">:</span> <span class="token string">"Max"</span><span class="token punctuation">}</span><span class="token punctuation">,</span> <span class="token punctuation">{</span><span class="token string-property property">"writeConcern"</span><span class="token operator">:</span> <span class="token punctuation">{</span><span class="token string-property property">"w"</span><span class="token operator">:</span> <span class="token string">"majority"</span><span class="token punctuation">,</span> <span class="token string-property property">"wtimeout"</span><span class="token operator">:</span> <span class="token number">5000</span><span class="token punctuation">}</span><span class="token punctuation">}</span><span class="token punctuation">)</span>
@ -138,7 +138,7 @@
<table><thead><tr><th align="left">Operator</th><th>Description</th><th>Commands</th></tr></thead><tbody><tr><td align="left"><code>$gt</code></td><td>比...更棒</td><td><code>db.docx.find({class:{$gt:'T'}</code></td></tr><tr><td align="left"><code>$gte</code></td><td>大于等于</td><td><code>db.docx.find({class:{$gt:'T'}</code></td></tr><tr><td align="left"><code>$lt</code></td><td>小于</td><td><code>db.docx.find({class:{$lt:'T'}</code></td></tr><tr><td align="left"><code>$lte</code></td><td>小于等于</td><td><code>db.docx.find({class:{$lte:'T'}</code></td></tr><tr><td align="left"><code>$exists</code></td><td>属性是否存在</td><td><code>db.docx.find({class:{$gt:'T'}</code></td></tr><tr><td align="left"><code>$regex</code></td><td>正则表达式匹配</td><td><code>db.docx.find({name:{$regex:'^USS\\sE'}})</code></td></tr><tr><td align="left"><code>$type</code></td><td>按元素类型搜索</td><td><code>db.docx.find({name : {$type:4}})</code></td></tr></tbody></table>
<table><thead><tr><th align="left">Operator</th><th>Description</th><th>Commands</th></tr></thead><tbody><tr><td align="left"><code>$gt</code></td><td>大于</td><td><code>db.docx.find({class:{$gt:'T'}</code></td></tr><tr><td align="left"><code>$gte</code></td><td>大于等于</td><td><code>db.docx.find({class:{$gt:'T'}</code></td></tr><tr><td align="left"><code>$lt</code></td><td>小于</td><td><code>db.docx.find({class:{$lt:'T'}</code></td></tr><tr><td align="left"><code>$lte</code></td><td>小于等于</td><td><code>db.docx.find({class:{$lte:'T'}</code></td></tr><tr><td align="left"><code>$exists</code></td><td>属性是否存在</td><td><code>db.docx.find({class:{$gt:'T'}</code></td></tr><tr><td align="left"><code>$regex</code></td><td>正则表达式匹配</td><td><code>db.docx.find({name:{$regex:'^USS\\sE'}})</code></td></tr><tr><td align="left"><code>$type</code></td><td>按元素类型搜索</td><td><code>db.docx.find({name : {$type:4}})</code></td></tr></tbody></table>
</div></div></div><div class="wrap h3body-not-exist col-span-3"><div class="wrap-header h3wrap"><h3 id="读取"><a aria-hidden="true" tabindex="-1" href="#读取"><span class="icon icon-link"></span></a>读取</h3><div class="wrap-body">
<!--rehype:wrap-class=col-span-3-->
<pre class="language-mongodb"><code class="language-mongodb code-highlight"><span class="code-line">db<span class="token punctuation">.</span><span class="token property-access">coll</span><span class="token punctuation">.</span><span class="token method function property-access">findOne</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token comment">// 返回单个文档</span>