當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。