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


TypeScript Db.collection方法代码示例

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


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

示例1: 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);
                });
            }
        });
开发者ID:biwin,项目名称:KandoeGroepJWebAndBackend,代码行数:15,代码来源:organisationDao.ts

示例2: callback

 this.client.connect(DaoConstants.CONNECTION_URL).then((db: Db) => {
     return db.collection('users').find({'_email': {'$in': _userEmailAdresses}}).project({'_id': 1}).toArray((err:MongoError, result:User[]) => {
         var ids:string[] = result.map(u => u._id.toString());
         db.close();
         callback(ids);
     });
 });
开发者ID:biwin,项目名称:KandoeGroepJWebAndBackend,代码行数:7,代码来源:userDao.ts

示例3: 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);
            });
        });
开发者ID:biwin,项目名称:KandoeGroepJWebAndBackend,代码行数:7,代码来源:groupDao.ts

示例4: 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);
            });
        });
开发者ID:biwin,项目名称:KandoeGroepJWebAndBackend,代码行数:7,代码来源:groupDao.ts

示例5: Error

    /**
     * @private
     */
    async update<T extends IModel>(manager: ModelManager, model: T, params: IUpdateParams, result: ModelOperationResult<T, IUpdateMeta>): Promise<ModelOperationResult<T, IUpdateMeta>> {
        if (!params.where) {
            throw new Error(`update() requires the 'where' option to be set.`);
        }

        let meta = manager.getModelMeta(model);
        const mongoQuery = convertQuery(manager, meta.ctor, params.where);

        const fieldUpdates: IKeyMap<any> = {};
        params.fields!.forEach((fieldName) => {
            const field = meta.fieldsByName[fieldName];
            if (field.options.stored && typeof model[fieldName] != 'undefined') {
                let value = field.toBackendValue(manager, model[fieldName]);
                if (typeof value != 'undefined') {
                    fieldUpdates[fieldName] = value;
                }
            }
        });

        const colName = this._getCollectionName(meta);
        const updateResult = await this.db.collection(colName).updateMany(mongoQuery, { $set: fieldUpdates });

        result.setMeta({ totalCount: updateResult.matchedCount });
        return result;
    }
开发者ID:RevFramework,项目名称:rev-framework,代码行数:28,代码来源:backend.ts

示例6: saveVote

export async function saveVote(vote: VoteDBEntry): Promise<VoteDBEntry | null> {
  const tokenCollection = db.collection(TOKEN_COLLECTION);
  const token = await tokenCollection.findOne({ token: vote.sessionId });
  if (!token) {
    console.log('Invalid sessionId in vote', vote);
    return null;
  }

  const voteCollection = db.collection(VOTE_COLLECTION);
  const oldVote = await voteCollection.findOne({ clientToken: vote.clientToken });
  if (oldVote) {
    voteCollection.deleteOne(oldVote);
  }
  voteCollection.insertOne(vote);
  return oldVote;
}
开发者ID:shybyte,项目名称:wahlomat,代码行数:16,代码来源:db.ts

示例7: callback

 this._client.connect(DaoConstants.CONNECTION_URL, (err:any, db:Db) => {
     db.collection('cardpositions').insertOne(cp, null, (err:MongoError, result:InsertOneWriteOpResult) => {
         cp._id = result.insertedId.toString();
         db.close();
         callback(cp);
     });
 });
开发者ID:biwin,项目名称:KandoeGroepJWebAndBackend,代码行数:7,代码来源:circleSessionDao.ts

示例8: callback

        this._client.connect(DaoConstants.CONNECTION_URL, (err: any, db: Db) => {
            db.collection('organisations').updateOne({'_groupIds': {'$in': [groupId]}}, {$pull: {'_groupIds': groupId}}, (error: MongoError, result: UpdateWriteOpResult) => {
                db.close();

                callback(result.modifiedCount == result.matchedCount && result.matchedCount == 1);
            });
        });
开发者ID:biwin,项目名称:KandoeGroepJWebAndBackend,代码行数:7,代码来源:organisationDao.ts


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