本文整理汇总了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);
});
},
};
}
示例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;
}
示例3: constructor
constructor(private collection: Collection) {
this.collection.createIndex({name: 1}, {unique: true});
}
示例4: constructor
constructor(private collection: Collection, private projectionType: ProjectionType) {
this.collection.createIndex({__id: 1}, {unique: true});
}
示例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 })
}
示例6: initDb
initDb() {
this.collection5v5 = this.db.collection('5v5');
this.collection5v5.createIndex({'r': 1, 'd': 1});
}
示例7: constructor
constructor(private collection: Collection) {
this.collection.createIndex({id: 1}, {unique: true});
this.collection.createIndex({sagaClass: 1, associationValues: 1});
}
示例8: constructor
constructor(private collection: Collection) {
this.collection.createIndex({id: 1});
this.collection.createIndex({id: 1, type: 1});
}
示例9: constructor
constructor(private collection: Collection, private serializer: Serializer, private eventClassMap: EventClassMap) {
this.collection.createIndex({token: 1}, {unique: true});
}