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

108
Views
Fetching documents from DB using a prop which is an object id

I get no results, and I don't know why. (DB has documents with this owner id) As you can see, I've tried using Types.ObjectId but no success yet.

export const getStores = async (
  { owner, platform }: {
    owner: string
    platform?: string
  }): Promise<StoreMainInfo[]> => {
  console.log('owner', owner); // owner 62210e86f36af71f58022971

  const stores = await StoreModel.aggregate([
    {
      '$project': {
        '_id': 1,
        'platform': 1,
        'name': 1,
        'category': 1,
        'logo': 1,
        'urls': 1,
        'stats': 1,
      }
    }, {
      $match: { owner: Types.ObjectId(owner) }
    },
  ]);

  if (!stores.length) {
    throw ApiError.BadRequest('Stores not found.');
  }

  return stores;
};

// Model:

    const StoreSchema: Schema = new Schema({
      owner: { type: Types.ObjectId, ref: CollectionNames.user, required: true },
      platform: { type: String, required: true },
      name: { type: String, required: true },
      category: { type: String, required: false },
      logo: { type: LogoSchema, required: false },
      urls: { type: UrlsSchema, required: true },
      stats: { type: StatsSchema, required: true },
      suppliers: { type: [SupplierSchema], required: true },
    })
    
    export default model<Document & Store>(CollectionNames.store, StoreSchema)


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!