<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>

                企業??AI智能體構建引擎,智能編排和調試,一鍵部署,支持知識庫和私有化部署方案 廣告
                [TOC=2,4] `think.model.mongo`?繼承類?[think.model.base](https://thinkjs.org/zh-CN/doc/2.0/api_model.html)。 ##### 使用 ES6 的語法繼承該類 ~~~ export default class extends think.model.mongo { getList(){ } } ~~~ ##### 使用普通方式繼承該類 ~~~ module.exports = think.model("mongo", { getList: function(){ } }) ~~~ ### 屬性 #### model.indexes 設置字段索引,數據操作之前會自動創建索引。 ~~~ export default class extends think.model.mongo { init(...args){ super.init(...args); //配置索引 this.indexes = { } } } ~~~ ##### 單字段索引 ~~~ export default class extends think.model.mongo { init(...args){ super.init(...args); //配置索引 this.indexes = { name: 1 } } } ~~~ ##### 唯一索引 通過?`$unique`?來指定為唯一索引,如: ~~~ export default class extends think.model.mongo { init(...args){ super.init(...args); //配置索引 this.indexes = { name: {$unique: 1} } } } ~~~ ##### 多字段索引 可以將多個字段聯合索引,如: ~~~ export default class extends think.model.mongo { init(...args){ super.init(...args); //配置索引 this.indexes = { email: 1 test: { name: 1, title: 1, $unique: 1 } } } } ~~~ #### model.pk 主鍵名,默認為?`_id`,可以通過?`this.getPk`?方法獲取。 ### 方法 #### model.where(where) mongo 模型中的 where 條件設置和關系數據庫中不太一樣。 ##### 等于判斷 ~~~ export default class extends think.model.mongo { where1(){ return this.where({ type: "snacks" }).select(); } } ~~~ ##### AND 條件 ~~~ export default class extends think.model.mongo { where1(){ return this.where({ type: "food", price: { $lt: 9.95 } }).select(); } } ~~~ ##### OR 條件 ~~~ export default class extends think.model.mongo { where1(){ return this.where({ $or: [ { qty: { $gt: 100 } }, { price: { $lt: 9.95 } } ] }).select(); } where2(){ return this.where({ type: "food", $or: [ { qty: { $gt: 100 } }, { price: { $lt: 9.95 } } ] }).select(); } } ~~~ ##### 內嵌文檔 ~~~ export default class extends think.model.mongo { where1(){ return this.where( { producer: { company: "ABC123", address: "123 Street" } }).select(); } where2(){ return this.where({ "producer.company": "ABC123" } ).select(); } } ~~~ ##### IN 條件 ~~~ export default class extends think.model.mongo { where1(){ return this.where({ type: { $in: [ "food", "snacks" ] } }).select(); } } ~~~ * * * 更多文檔請見?[https://docs.mongodb.org/manual/reference/operator/query/#query-selectors](https://docs.mongodb.org/manual/reference/operator/query/#query-selectors)。 #### model.collection() * `return`?{Promise} 獲取操作當前表的句柄。 ~~~ export default class extends think.model.mongo { async getIndexes(){ let collection = await this.collection(); return collection.indexes(); } } ~~~ #### model.aggregate(options) 聚合查詢。具體請見?[https://docs.mongodb.org/manual/core/aggregation-introduction/](https://docs.mongodb.org/manual/core/aggregation-introduction/)。 #### model.mapReduce(map, reduce, out) mapReduce 操作,具體請見?[https://docs.mongodb.org/manual/core/map-reduce/](https://docs.mongodb.org/manual/core/map-reduce/)。 #### model.createIndex(indexes, options) * `indexes`?{Object} 索引配置 * `options`?{Object} 創建索引。 #### model.getIndexes() * `return`?{Promise} 獲取索引。 文檔地址:[https://github.com/75team/www.thinkjs.org/tree/master/view/zh-CN/doc/2.0/api_model_mongo.md](https://github.com/75team/www.thinkjs.org/tree/master/view/zh-CN/doc/2.0/api_model_mongo.md)
                  <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>

                              哎呀哎呀视频在线观看