本文整理汇总了TypeScript中mongodb.MongoClient.db方法的典型用法代码示例。如果您正苦于以下问题:TypeScript MongoClient.db方法的具体用法?TypeScript MongoClient.db怎么用?TypeScript MongoClient.db使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongodb.MongoClient
的用法示例。
在下文中一共展示了MongoClient.db方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getInternalCollection
public async getInternalCollection(
schemaName: string,
collectionName: string,
) {
const db = this.client.db(schemaName)
return await db.collection<Data>(collectionName)
}
示例2: getInternalCollections
public async getInternalCollections(schemaName: string) {
const db = this.client.db(schemaName)
const collections = (await db.collections()) as Collection<Data>[]
return collections.map(collection => {
return { name: collection.collectionName, collection }
})
}
示例3: listSchemas
async listSchemas(): Promise<string[]> {
const adminDB = this.client.db().admin()
const { databases } = await adminDB.listDatabases()
return databases
.map(x => x.name)
.filter(x => reservedSchemas.indexOf(x) < 0)
}
示例4: connect
async connect(uri: string, user?: string, password?: string) {
if (!this.db) {
let options: MongoClientOptions = { autoReconnect: true, ...(user && password ? { auth: { user, password } } : {}) };
this.mongoClient = await MongoClient.connect(uri, options)
this.db = this.mongoClient.db()
await createIndexes()
}
}
示例5: connect
/**
* Initialises the connection to the MongoDB server
*/
async connect() {
this.client = await MongoClient.connect(this.config.url, this.config.options);
this.db = this.client.db(this.config.dbName);
}
示例6: getSchema
public getSchema() {
return this.client.db(this.schema)
}
示例7: constructor
constructor(client: MongoClient, dbName: string) {
this.client = client;
this.db = client.db(dbName);
}
示例8: constructor
constructor(client: MongoClient) {
this.users = client.db().collection('users');
}