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

114
Views
How to connect two MongoDb collections?

I need to know how to add two database collections in MongoDB. Here is my code

async function run2(){
try {
    await client.connect();
  
    const itemCollection2 = client.db('warehouse_inventory').collection('myCollection');

    // for my items
    app.post('/items', async (req, res)=>{
        const newItem = req.body;
        const result = await itemCollection2.insertOne(newItem);
        res.send(result);
    })
   

}
finally {

}

}

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

0

to add or create others database just take a const and change collaction name it will be create database automaticely . to use use that const name to your api cursor

async function run2(){
try {
   await client.connect();
   const otheritemCollection = 
   client.db('warehouse_inventory').collection('myCollection2');

    // for my other db
    app.post('/items', async (req, res)=>{
    const newItem = req.body;
    const result = await otheritemCollection.insertOne(newItem);
    res.send(result);
   })

}
finally {

} }

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!