本文整理汇总了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);
});
}
});
示例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);
});
});
示例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);
});
});
示例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);
});
});
示例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;
}
示例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;
}
示例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);
});
});
示例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);
});
});