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 {
}
}
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 {
} }