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

155
Views
mongoose router find by reference properety

I am working in my project I already wrote the server.js file for backend this is my mongoose schema and model

const BookSchema = new mongoose.Schema({
title: {
  type: String,
  required: true
},
isbn: {
  type: String,
  required: true
},
author: {
  type: String,
  //required: true
},
description: {
  type: String
},
published_date: {
  type: Date
},
publisher: {
  type: String
},
updated_date: {
  type: Date,
  default: Date.now
}
});

// make data model from schema
const Book = mongoose.model('book', BookSchema);

this is my router

router.get('/:id', (req, res) => {


 Book.findById(req.params.id)
.then(book => res.json(book.title))
.catch(err => res.status(404).json({ nobookfound: 'No Book found' }));
});

How can I pass Book.isbn through get request to get Book.title

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

0

just use the findOne method

Book.findOne({isbn:"pass isbn value here"})
.then(book => res.json(book.title))
.catch(err => res.status(404).json({ nobookfound: 'No Book found' }));
});
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!