本文整理匯總了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);
}