<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 文檔(documents) > 原文:[Documents](http://mongoosejs.com/docs/documents.html) > 翻譯:小蝦米(QQ:509129) ## Documents Mongoose[文檔](http://mongoosejs.com/docs/api.html#document-js)代表了文檔存儲在MongoDB的一對一映射。每個文檔都是它的[模型](http://mongoosejs.com/docs/models.html)的一個實例。 ### 檢索 有許多方法從MongoDB文檔檢索。我們不會涵蓋在在這一部分中。查看查詢詳細信息的[‘querying’](http://mongoosejs.com/docs/queries.html)章節。 ### 更新 有一些方法來更新文檔。我們先看看使用`findById`的傳統方法: ``` Tank.findById(id, function (err, tank) { if (err) return handleError(err); tank.size = 'large'; tank.save(function (err) { if (err) return handleError(err); res.send(tank); }); }); ``` 這種方法包括首先檢索文檔從Mongo,然后發出更新命令(通過觸發調用保存)。然而,如果我們不需要的文檔在我們的應用程序中返回,只需要更新一個屬性直接在數據庫、`Model#update`對我們是正確的: ``` Tank.update({ _id: id }, { $set: { size: 'large' }}, callback); ``` 如果我們的應用程序需要文檔返回,則需要另一個方法,往往[更好](http://mongoosejs.com/docs/api.html#model_Model.findByIdAndUpdate),選項: ``` Tank.findByIdAndUpdate(id, { $set: { size: 'large' }}, function (err, tank) { if (err) return handleError(err); res.send(tank); }); ``` `findAndUpdate/Remove` 靜態方法都在最多一個文檔中進行更改,并返回它只有一個調用數據庫。有幾種不同的`findandmodify`主題。閱讀[API文檔](http://mongoosejs.com/docs/api.html)的更多細節。注意`findAndUpdate/Remove`不執行任何鉤子或驗證在在數據庫中進行更改 之前。如果你需要鉤子和驗證,首先查詢文檔,然后保存它。 > 譯者注:[findByIdAndRemove](http://mongoosejs.com/docs/api.html#model_Model.findByIdAndRemove),[findOneAndUpdate](http://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate),[findAndModify](https://docs.mongodb.com/manual/reference/command/findAndModify/) ### 驗證 在保存文檔之前,文檔進行了驗證。詳情閱讀[API文檔](http://mongoosejs.com/docs/api.html#document_Document-validate)或[validation](http://mongoosejs.com/docs/validation.html)章節。 ### 下一步 既然我們已經掌握了文檔,讓我們看看[子文檔](http://mongoosejs.com/docs/subdocs.html)。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看