當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。