当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Collection.drop方法代码示例

本文整理汇总了TypeScript中mongodb.Collection.drop方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Collection.drop方法的具体用法?TypeScript Collection.drop怎么用?TypeScript Collection.drop使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mongodb.Collection的用法示例。


在下文中一共展示了Collection.drop方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: genId

MongoClient.connect('mongodb://localhost:27017/' + (mode == DBMode.RacerTable ? 'racer' : 'team')).then((db:Db)=> {

    let col:Collection = db.collection('ski');
    
    // delete the collection and then repopulate it
    col.drop().catch(err => err).then(() => {
        console.log('Start DB Creation');
        console.time('Create DB');
        let completedCreation:Promise<any>;
        if (mode == DBMode.RacerTable) {
            
            let toAdd:Array<IndependentRacer> = new Array<IndependentRacer>();
            for (let team = 0; team < teams; ++team) {
                // generate team id
                let teamId = genId(team);
                for (let racer = 0; racer < racersATeam; ++racer) {
                    // generate racer
                    toAdd.push(generateIndependentRacer(teamId, genId(team * racersATeam + racer)));
                }
            }
            console.log('Racer Obj Created, Inserting');
            completedCreation = Promise.all([col.insertMany(toAdd), col.createIndex('id')]);
            
        } else {
            
            let toAdd:Array<Team> = new Array<Team>();
            for (let team = 0; team < teams; ++team) {
                // create team, generate id
                let newTeam:Team = new Team(genId(team), []);
                toAdd.push(newTeam);
                for (let racer = 0; racer < racersATeam; ++racer) {
                    // add random racers to team
                    newTeam.racers.push(generateRacer(genId(team * racersATeam + racer)));
                }
            }
            console.log('Teams Obj Created, Inserting');
            completedCreation = Promise.all([col.insertMany(toAdd), col.createIndex('racers.id'), col.createIndex('id')]);
        }
        // once the collection and indices have been created, run our tests
        completedCreation.then(() => {
            console.timeEnd('Create DB');

            // create the threads that will access the database
            let threads:Array<ChildProcess> = new Array<ChildProcess>();
            console.log("Creating Threads");
            for (let i = 0; i < threadCount; ++i) {
                let new_child:ChildProcess;
                if (mode == DBMode.RacerTable) {
                    new_child = fork('./stress-test-racer');
                } else if (mode == DBMode.TeamTable) {
                    new_child = fork('./stress-test-team');
                }
                new_child.send({
                    type:             'generate',
                    teams:            teams,
                    racersATeam:      racersATeam,
                    updateQueryRatio: updateQueryRatio,
                    thisThreadNum:    i,
                    totalThreads:     threadCount,
                    accessCount:      accessCount
                });
                threads.push(new_child);
            }
            // run the three tests once after another
            async.series([
                (callback:(err:Error)=>void) => {
                    // Wait for all threads to be ready
                    Promise.all(threads.map(thread=>new Promise((resolve, reject)=> {
                        thread.once('message', (msg:string) => msg === 'ready' ? resolve() : reject())
                    }))).then(() => {
                        console.log('All Threads Ready');
                        callback(null);
                    }).catch(() => callback(new Error('Thread Error')));
                },
                (callback:(err:Error)=>void) => {
                    console.time("Update from all Threads");
                    Promise.all(threads.map(thread=>new Promise((resolve, reject)=> {
                        thread.send('update');
                        thread.once('message', (msg:string) => msg === 'update' ? resolve() : reject());
                    }))).then(() => {
                        console.timeEnd("Update from all Threads");
                        callback(null);
                    }).catch(() => callback(new Error('Thread Error')));
                },
                (callback:(err:Error)=>void) => {
                    console.time("Query from all Threads");
                    Promise.all(threads.map(thread=>new Promise((resolve, reject)=> {
                        thread.send('query');
                        thread.once('message', (msg:string) => msg === 'query' ? resolve() : reject());
                    }))).then(()=> {
                        console.timeEnd("Query from all Threads");
                        callback(null);
                    }).catch(() => callback(new Error('Thread Error')));
                },
                (callback:(err:Error)=>void) => {
                    console.time("Update and Query from all Threads");
                    Promise.all(threads.map(thread=>new Promise((resolve, reject)=> {
                        thread.send('both');
                        thread.once('message', (msg:string) => msg === 'both' ? resolve() : reject());
                    }))).then(()=> {
//.........这里部分代码省略.........
开发者ID:Tiedye,项目名称:RazzieTest,代码行数:101,代码来源:index.ts

示例2: clear

 public async clear(): Promise<void> {
     return this.collection.drop();
 }
开发者ID:martyn82,项目名称:aphajs,代码行数:3,代码来源:MongoDbProjectionStorage.ts


注:本文中的mongodb.Collection.drop方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。