当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Collection.createIndex方法代码示例

本文整理汇总了TypeScript中mongodb.Collection.createIndex方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Collection.createIndex方法的具体用法?TypeScript Collection.createIndex怎么用?TypeScript Collection.createIndex使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mongodb.Collection的用法示例。


在下文中一共展示了Collection.createIndex方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: shared

export function shared(coll: Collection): Cache<Object> {
    coll.createIndex(IDX_COLL, IDX_CONF);

    return {
        get: function (name) {
            return new Promise((resolve, reject) => {
                coll.find({ name })
                    .next()
                    .then(item => resolve(item ? item.value : undefined))
                    .catch(reject);
            });
        },

        set: function (name, value, { ttl = 3600000 }) {
            return new Promise<boolean>((resolve, reject) => {
                var filter = { name },
                    update = gen_item(name, value, ttl),
                    option = { upsert: true };

                coll.findOneAndUpdate(filter, update, option)
                    .then(() => resolve(true))
                    .catch(reject);
            });
        },
    };
}
开发者ID:consumr-project,项目名称:cp,代码行数:26,代码来源:cache.ts

示例2: checkCollectionIndexes

  async checkCollectionIndexes(coll:Collection): Promise<any> {
    const indexes = this.getIndexes();
    if (indexes && indexes.length) {
      let currIndexes;
      try {
        currIndexes = await coll.indexes();
      } catch(e) {
        currIndexes = [];
      }
      for (let i of indexes) {
        const props = [ 'unique', 'sparse', 'min', 'max', 'expireAfterSeconds', 'key' ];

        let c_i = currIndexes.find(t => {
          return (typeof i.name === 'undefined' || i.name === t.name) && _.isEqual(_.pick(i, props), _.pick(t, props));
        });
        if (!c_i) {
          if (this.createIndexes) {
            logger.info(this.name, 'creating missing index', i);
            await coll.createIndex(i.key, _.omit(i, 'key'));
          } else {
            logger.warn(this.name, 'missing index', i);
          }
        }
      }
    }
    this[__indexesChecked] = true;
  }
开发者ID:vivocha,项目名称:arrest,代码行数:27,代码来源:resource.ts

示例3: constructor

 constructor(private collection: Collection) {
     this.collection.createIndex({name: 1}, {unique: true});
 }
开发者ID:martyn82,项目名称:aphajs,代码行数:3,代码来源:MongoDbVersionStorage.ts

示例4: constructor

 constructor(private collection: Collection, private projectionType: ProjectionType) {
     this.collection.createIndex({__id: 1}, {unique: true});
 }
开发者ID:martyn82,项目名称:aphajs,代码行数:3,代码来源:MongoDbProjectionStorage.ts

示例5: createIndexes

  private createIndexes() {
    this.sessionCollection.createIndex({ sessionId: 1 })

    this.tradeCollection.createIndex({ id: 1 }, { unique: true })
    this.tradeCollection.createIndex({ exchange: 1, symbol: 1, timestamp: 1 })

    this.markerCollection.createIndex({ exchange: 1, symbol: 1, to: 1 })
    this.markerCollection.createIndex({ exchange: 1, symbol: 1, from: 1 })

    this.orderCollection.createIndex({ sessionId: 1 })
    this.orderCollection.createIndex({ sessionId: 1, exchange: 1, symbol: 1, timestamp: 1 })

    this.walletCollection.createIndex({ sessionId: 1 })
    this.walletCollection.createIndex({ sessionId: 1, exchange: 1, symbol: 1, strategy: 1 })

    this.adjustmentCollection.createIndex({ sessionId: 1 })
    this.adjustmentCollection.createIndex({ sessionId: 1, exchange: 1, symbol: 1, strategy: 1, timestamp: 1 })

    this.exchangeCollection.createIndex({ sessionId: 1 })
    this.exchangeCollection.createIndex({ sessionId: 1, exchange: 1 })

    this.strategyCollection.createIndex({ sessionId: 1 })
    this.strategyCollection.createIndex({ sessionId: 1, exchange: 1 })
    this.strategyCollection.createIndex({ sessionId: 1, exchange: 1, symbol: 1, strategy: 1 })
  }
开发者ID:magic8bot,项目名称:magic8bot,代码行数:25,代码来源:mongo.lib.ts

示例6: initDb

 initDb() {
     this.collection5v5 = this.db.collection('5v5');
     this.collection5v5.createIndex({'r': 1, 'd': 1});
 }
开发者ID:papajuras,项目名称:dota2stats,代码行数:4,代码来源:DbHandler.ts

示例7: constructor

 constructor(private collection: Collection) {
     this.collection.createIndex({id: 1}, {unique: true});
     this.collection.createIndex({sagaClass: 1, associationValues: 1});
 }
开发者ID:martyn82,项目名称:aphajs,代码行数:4,代码来源:MongoDbSagaStorage.ts

示例8: constructor

 constructor(private collection: Collection) {
     this.collection.createIndex({id: 1});
     this.collection.createIndex({id: 1, type: 1});
 }
开发者ID:martyn82,项目名称:aphajs,代码行数:4,代码来源:MongoDbEventStorage.ts

示例9: constructor

 constructor(private collection: Collection, private serializer: Serializer, private eventClassMap: EventClassMap) {
     this.collection.createIndex({token: 1}, {unique: true});
 }
开发者ID:martyn82,项目名称:aphajs,代码行数:3,代码来源:MongoDbScheduleStorage.ts


注:本文中的mongodb.Collection.createIndex方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。