Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

157
Views
.findOne / .findById sigue ejecutándose si no se encuentra ningún resultado

Me enfrento a un problema que no puedo resolver solo.

Tengo una colección MongoDB, en esta colección tengo 1 documento atm.

Cuando uso .findById(_id) o .findOne({_id : id}) con el _id correcto, todo funciona.

.findById(_id) .findOne({_id : id}) .

¡Ty por tu tiempo, cuídate!

EDITAR :

  • Documento :
 export interface OrderDocument extends mongoose.Document { user: UserDocument['_id']; asset_bought: AssetDocument['_id']; asset_b_symbol: string; asset_sold: AssetDocument['_id']; asset_s_symbol: string; exchange: ExchangeDocument['_id']; exchange_name: string; is_draft: Boolean; amount: number; atm_price: number; date: Date; }
  • Esquema de la colección:
 const orderSchema = new mongoose.Schema( { _id: { type: mongoose.Schema.Types.ObjectId }, user: { type: mongoose.Schema.Types.ObjectId, ref: 'users', required: true, }, asset_bought: { type: mongoose.Schema.Types.ObjectId, ref: 'assets', required: true, }, asset_b_symbol: { type: String, required: true, }, asset_sold: { type: mongoose.Schema.Types.ObjectId, ref: 'assets', required: true, }, asset_s_symbol: { type: String, required: true, }, exchange: { type: mongoose.Schema.Types.ObjectId, ref: 'exchanges', required: true, }, exchange_name: { type: String, required: true, }, is_draft: { type: Boolean, default: false }, amount: { type: Number, required: true }, atm_price: { type: Number, required: true }, date: { type: Date, required: true }, }, { timestamps: true } );
  • Servicio
 export async function findAndPopulateOrders( searchType: 'id' | 'one' | 'many', query: FilterQuery<OrderDocument>, _collections: Array<string> ) { const collections = _collections.join(' '); if (searchType === 'id') { return await OrderModel.findById(query).populate(collections); } else if (searchType === 'one') { return await OrderModel.findOne(query).populate(collections); } else if (searchType === 'many') { return await OrderModel.find(query).populate(collections); } else { return {}; } }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!