本文整理汇总了TypeScript中mongoose.Model.find方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Model.find方法的具体用法?TypeScript Model.find怎么用?TypeScript Model.find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongoose.Model
的用法示例。
在下文中一共展示了Model.find方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: list
export function list(req: Request, res: Response): void {
let params = UTIL.assembleSearchParams(req, {
status: CONST.STATUSES.CONSUMER.ACTIVE
}, 'handle')
const UserModel: Model<IUser> = UTIL.getModelFromName(req.routeVar.userType)
UserModel
.find(params.query)
.skip(params.skip)
.limit(params.limit)
.sort(params.sort)
.lean()
.exec()
.then((data: IUser[]) => {
if (data) {
res.status(200).json(data)
} else {
res.status(404).send()
}
})
.catch((err: Error) => {
res.status(res.statusCode).send()
console.log(err)
})
}
示例2:
const search = (req: Request, res: Response, creator?: Schema.Types.ObjectId) => {
let params = UTIL.assembleSearchParams(req, {
status: CONST.STATUSES.CONTENT.APPROVED
}, req.routeVar.keywordFields)
if (creator) {
params.query.creator = creator
}
const DataModel: Model<IContent> = UTIL.getModelFromName(req.routeVar.contentType)
DataModel
.find(params.query)
.skip(params.skip)
.limit(params.limit)
.sort(params.sort)
.populate({
path: 'creator',
model: CONST.USER_TYPES.CONSUMER,
select: CONST.PUBLIC_CONSUMER_INFO_LIST
})
.lean()
.exec()
.then((data: IContent[]) => {
if (data) {
res.status(200).json(data)
} else {
res.status(404).send()
}
})
.catch((err: Error) => {
res.status(res.statusCode).send()
console.log(err)
})
}
示例3: errorCb
searchDocuments<T extends Document>(model: Model<T>, filter: any, errorCb: (err: any) => void, successCb: (data: any) => void, options?: IOptions) {
let query = model.find(filter);
query.skip(Utils.isNumber(options.skip) ? options.skip : 0)
.limit(Utils.isNumber(options.limit) ? options.limit : 1000)
.exec((err: any, data: any[]) => {
err ? errorCb(err) : successCb(data);
});
}
示例4: reject
return new Promise<string[]>((resolve: Function, reject: Function) => {
const txModelOptions = this.obtainTransactionModelOptions(newOptions);
const authorizationResponse = this.isSearchAuthorized(txModelOptions);
if (!authorizationResponse.isAuthorized) {
return reject(new Error(authorizationResponse.errorMessage));
}
this.addAuthorizationDataPreSearch(txModelOptions);
this.transactionModelOptionsAddData(data, txModelOptions);
const search = this.obtainSearchExpression(data, txModelOptions);
this.Model.find(search).distinct(txModelOptions.distinct)
.exec((err, foundObjs) => {
if (err) {
return reject(err);
}
resolve(foundObjs);
});
});
示例5: reject
return new Promise<T[]>((resolve: Function, reject: Function) => {
const txModelOptions = this.obtainTransactionModelOptions(newOptions);
const authorizationResponse = this.isSearchAuthorized(txModelOptions);
if (!authorizationResponse.isAuthorized) {
return reject(new Error(authorizationResponse.errorMessage));
}
this.addAuthorizationDataPreSearch(txModelOptions);
this.transactionModelOptionsAddData(data, txModelOptions);
const search = this.obtainSearchExpression(data, txModelOptions);
this.Model.find(search, txModelOptions.projection,
{ sort: '-createdAt', lean: true }).populate(txModelOptions.population)
.exec((err, foundObjs) => {
if (err) {
return reject(err);
}
resolve(foundObjs);
});
});
示例6: list
public async list(options = {}) : Promise<Document[]> {
let paths = this.getPathsToPopulate();
return await this.Model.find(options).populate(paths.join(', ')).exec();
}
示例7: find
find(callback: (error: any, result: any) => void) {
this._model.find({}, callback);
}