本文整理汇总了TypeScript中mongodb.Db类的典型用法代码示例。如果您正苦于以下问题:TypeScript Db类的具体用法?TypeScript Db怎么用?TypeScript Db使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Db类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: save
async save(todo:TodoModel):Promise<TodoModel> {
let db: Db = await this.mongoDataSource.getConnection();
let insert = { name : todo.name, description : todo.description, completed : todo.completed };
let persistedTodo = await db.collection('todoCollection').insertOne(insert);
let persistedTodoId: string = persistedTodo.insertedId.toString();
return await this.get(persistedTodoId);
}
示例2: update
async update(todo:TodoModel):Promise<TodoModel> {
let db: Db = await this.mongoDataSource.getConnection();
let query = { "_id" : new ObjectID(todo.id) };
let update = { $set: { name : todo.name, description : todo.description, completed : todo.completed } };
let persistedTodo = await db.collection('todoCollection').findOneAndUpdate(query, update);
return this.get(persistedTodo.value._id.toString());
}
示例3: analysisAllUserAsyncAwait
//async/await 类 async.whilst 方式遍历
export default async function analysisAllUserAsyncAwait() {
let endtime = new Date().getTime() / 1000;
let arg = await GetDB("bi");
let db: Db = arg.db as Db;
let LastAnalysisTimeCol: Collection = db.collection('lastanalysistime');
let AccountCol: Collection = db.db("user").collection('account');
//上次分析时间
let begintime: any = await new Promise((resolve, reject) => {
LastAnalysisTimeCol.findOne({ jobtype: "user" }, (err, lastinfo) => {
begintime = (lastinfo) ? lastinfo.time : 0; //有数据,从这数据开始,到现在。
resolve(begintime);
})
});
//要分析的telphone
let telphones: any = await new Promise((resolve, reject) => {
return new Promise((resolve, reject) => {
AccountCol.distinct('telphone', (err, telphones) => {
resolve(telphones);
})
})
});
//遍历分别更新
(function () {
let num = -1;
return Async.whilst(
function () { return (num++ < telphones.length - 1); },
function () {
return new Promise((resolve, reject) => {
accessWebAPI('www.google.com', '/bytelphone/' + telphones[num], 'GET', null, function (err, apidata) {
if (!err && apidata.item) {
resolve(apidata.item);
} else {
resolve(null);
}
})
}).then((item: any) => {
let lastVisitAt = (new Date(item.lastVisitAt)).getTime() / 1000;
return new Promise((resolve, reject) => {
AccountCol.update({ _id: item.id }, { $set: { field: item.field } }, (err, count) => {
resolve(count);
})
})
})
}
)
})()
//更新时间
await new Promise((resolve, reject) => {
LastAnalysisTimeCol.update({ jobtype: "user" }, { $set: { time: endtime } }, { upsert: true }, (err, doc) => {
resolve();
})
});
//清理连接
db.close();
}
示例4: ObjectID
this._client.connect(DaoConstants.CONNECTION_URL, (err: any, db: Db) => {
if(isAdmin) {
db.collection('organisations').updateOne({'_id': new ObjectID(organisationId)}, {$push: {'_organisatorIds': userId}}, (error: MongoError, result: UpdateWriteOpResult) => {
db.close();
callback(result.modifiedCount == 1);
});
} else {
db.collection('organisations').updateOne({'_id': new ObjectID(organisationId)}, {$push: {'_memberIds': userId}}, (error: MongoError, result: UpdateWriteOpResult) => {
db.close();
callback(result.modifiedCount == 1);
});
}
});
示例5: callback
this._client.connect(DaoConstants.CONNECTION_URL, (err:any, db:Db) => {
db.collection('circlesessions').insertOne(circleSession, (err:MongoError, res:InsertOneWriteOpResult) => {
circleSession._id = res.insertedId.toString();
db.close();
callback(circleSession);
});
});
示例6: ObjectID
this._client.connect(DaoConstants.CONNECTION_URL, (err:any, db:Db) => {
db.collection('circlesessions').updateOne({_id: new ObjectID(circleSessionId)},
{$set:{_inProgress: inProgress}}, (err:MongoError, res:UpdateWriteOpResult) => {
db.close();
callback();
});
});
示例7: callback
this._client.connect(DaoConstants.CONNECTION_URL, (err: any, db: Db) => {
db.collection('groups').find({'_organisationId': organisationId}).toArray((err: MongoError, docs: Group[]) => {
db.close();
callback(docs);
});
});
示例8: ObjectID
this._client.connect(DaoConstants.CONNECTION_URL, (err: any, db: Db) => {
db.collection('groups').deleteOne({'_id': new ObjectID(groupId)}, (err: MongoError, result: DeleteWriteOpResultObject) => {
db.close();
callback(result.deletedCount == 1);
});
});
示例9: findArray
/**
* ドキュメントを検索して複数の項目を取得します
*/
async findArray(collectionName: string, query: { [x: string]: any }, options?: IFindArrayOptions): Promise<any[]> {
options = options || {};
if (options.since != null || options.until != null) {
query._id = {};
}
if (options.since != null) {
query._id.$gt = options.since;
}
if (options.until != null) {
query._id.$lt = options.until;
}
let cursor = this.db.collection(collectionName).find(query);
if (options.limit != null)
cursor = cursor.limit(options.limit);
if (options.isAscending != null)
cursor = cursor.sort(MongoProvider.buildSortOption(options.isAscending));
const documents = await cursor.toArray();
return documents;
}