本文整理匯總了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');
}