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

143
Views
MongoDB connect model with a especific database

When I use mongoose.connection, models are connected directly with the unique connection. In this case db1 is only used for quering (not model require). But db2 use 2 models. ¿How Can I connect those models with db2 only?

Thanks for helping

const db1 = mongoose.createConnection("atlasuri").asPromise()
const db2 = mongoose.createConnection("localuri").asPromise()

app.get("/",async(req,res)=>{
    const finded =  (await db1).collection("users")
    await finded.forEach(el=> console.log(el))
    res.json(finded)
})

Models

const Criterion1=new mongoose.model('Criterion',new mongoose.Schema({
 name:string
}));
const User=new mongoose.model('Criterion',new mongoose.Schema({
 name:string
}));
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!