本文整理汇总了TypeScript中mongodb.Db.close方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Db.close方法的具体用法?TypeScript Db.close怎么用?TypeScript Db.close使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongodb.Db
的用法示例。
在下文中一共展示了Db.close方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: callback
db.collection('organisations').find({'$or': [{'_organisatorIds': {'$in': [userId]}}, {'_memberIds': {'$in': [userId]}}]}).project({'_id': 1}).toArray((err: MongoError, docs: Organisation[]) => {
var ids: string[] = docs.map( o => o._id.toString());
db.close();
callback(ids);
});
示例2: disconnect
disconnect() {
this.docFetcher.disconnect()
if (this.db) {
this.db.close()
this.db = null
}
}
示例3: clearJobs
clearJobs(() => {
mongo.close(() => {
jobs.stop();
jobs._mdb.close(done);
jobs = null;
});
});
示例4: callback
db.collection('cards').insertOne(card, (err: MongoError, result: InsertOneWriteOpResult) => {
card._id = result.insertedId.toString();
db.close();
callback(card);
});
示例5: callback
db.collection('organisations').insertOne(o, (error: MongoError, result) => {
if (error != null) {
console.warn(error.message);
}
o._id = result.insertedId;
db.close();
callback(o);
});
示例6: close
async close(): Promise<void> {
this.getConnection = () => Promise.reject(new Error('Connection closed'));
if (this._connection) {
await this._connection.close();
this._connection = undefined;
} else if (this._connecting) {
await this._connecting;
await this.close();
}
}
示例7: 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();
}