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

236
Views
How to get id from client?(express and mongoose)

I wrote a code to find the recipes base on the materials(this a object that i created before) but I wrote the object id in the code. I want client send me this id. how can i write my code in this way?

const Admin = require('../middleware/admin')
const Auth = require('../middleware/auth')
const express = require('express');
const { Recipe, validate } = require('../models/recipes');
const router = express.Router();


router.get('/',async(req,res)=>{
    const recipefound=await Recipe.find({materials:'62b703256f9ea31a51adde62'})//The object id
                                                 // ^^^^^^^^^^^^^^^^^^^^^^^^

    res.send(recipefound);
    

});

module.exports = router;


about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can send the client ID from front end in request params. Example: http:yourdomain:port/route/:recipeID

In backend you can handle like this:

router.get('/',async(req,res)=>{
    const recipefound=await Recipe.find({materials: req.params.recipeID})

    res.send(recipefound);
});
about 4 years ago · Juan Pablo Isaza Report
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!