本文整理汇总了TypeScript中mongoose.Model.findById方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Model.findById方法的具体用法?TypeScript Model.findById怎么用?TypeScript Model.findById使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mongoose.Model
的用法示例。
在下文中一共展示了Model.findById方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: view
public async view(id) : Promise<Document> {
if (!Types.ObjectId.isValid(id)) {
throw new Error('Unknown Record');
}
let paths = this.getPathsToPopulate();
return await this.Model.findById(id).populate(paths.join(', '));
}
示例2: reject
return new Promise<T>((resolve: Function, reject: Function) => {
const authorizationResponse = this.isUpdateAuthorized(newOptions);
if (!authorizationResponse.isAuthorized) {
return reject(new Error(authorizationResponse.errorMessage));
}
this.Model.findById(data._id, newOptions.projection)
.exec((err: Error, foundObj: any) => {
if (err) {
return reject(err);
}
if (ObjectUtil.isBlank(foundObj)) {
return reject(new Error('Object could not be found'));
}
if (newOptions.validatePostSearchAuthData) {
const authorizationResponse = this.validateAuthDataPostSearchUpdate(newOptions, foundObj);
if (!authorizationResponse.isAuthorized) {
return reject(new Error(authorizationResponse.errorMessage));
}
}
resolve(foundObj);
});
});
示例3: sublist
export function sublist(req: Request, res: Response): void {
const [user, ref] = UTIL.getLoginedUser(req),
UserModel: Model<IUser> = UTIL.getModelFromName(ref),
path = req.params.sublist,
model = UTIL.getModelNameFromPath(path),
opt: any = UTIL.assembleSearchParams(req),
select: string = UTIL.getSelectFieldsFromPath(path)
UserModel
.findById(user)
.select('handle')
.populate({
path,
model,
options: {
sort: opt.sort,
limit: opt.limit,
skip: opt.skip
},
populate: ({
path: 'target',
select
})
})
.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)
})
}
示例4: read
public async read(id) {
if (!Types.ObjectId.isValid(id)) {
throw new Error('Unknown Record');
}
return await this.Model.findById(id).exec();
}
示例5: findById
findById(_id: string, callback: (error: any, result: T) => void) {
this._model.findById(_id, callback);
}
示例6: findById
async findById(id: string): Promise<Document> {
return await this.model.findById(id).exec();
}
示例7: errorCb
findDocumentById<T extends Document>(model: Model<T>, id: string, errorCb: (err: any) => void, successCb: (data: any) => void) {
model.findById(id, (err: any, data: any) => {
err ? errorCb(err) : successCb(data);
});
}
示例8: findById
async findById(id: string) {
return await this.mongoModel.findById(id);
}
示例9: getById
static getById(model:Model, id:string, done) {
model.findById(id, done);
}