当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript Model.find方法代码示例

本文整理汇总了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)
  })
}
开发者ID:yeegr,项目名称:SingularJS,代码行数:26,代码来源:UserController.ts

示例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)
  })  
}      
开发者ID:yeegr,项目名称:SingularJS,代码行数:35,代码来源:ContentController.ts

示例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);
         });
 }
开发者ID:EmcaBorg,项目名称:got,代码行数:8,代码来源:dal.ts

示例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);
			});
		});
开发者ID:australdev,项目名称:app,代码行数:17,代码来源:base_service.ts

示例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);
			});
		});
开发者ID:jnamla,项目名称:herokuTestCymplar,代码行数:18,代码来源:base_service.ts

示例6: list

 public async list(options = {}) : Promise<Document[]> {
     let paths = this.getPathsToPopulate();
     return await this.Model.find(options).populate(paths.join(', ')).exec();
 }
开发者ID:rajivnarayana,项目名称:express-mongoose-scaffold,代码行数:4,代码来源:module.ts

示例7: find

 find(callback: (error: any, result: any) => void) {
     this._model.find({}, callback);
 }
开发者ID:yeshzaoui,项目名称:typescript-express-mongoose-bookapi,代码行数:3,代码来源:baseRepository.ts


注:本文中的mongoose.Model.find方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。