1 | initial version |
You can link to two distinct MongoDB databases in your Nuxt 3/ Vue 3 application by following these steps:
npm install mongodb
import { MongoClient } from 'mongodb';
const client1 = await MongoClient.connect('<first connection string>');
const db1 = client1.db('<first database name>');
const client2 = await MongoClient.connect('<second connection string>');
const db2 = client2.db('<second database name>');
const collection1 = db1.collection('<collection name>');
const collection2 = db2.collection('<collection name>');
// Query collection1:
const documents1 = await collection1.find({}).toArray();
// Query collection2:
const documents2 = await collection2.find({}).toArray();
You can call these database connections and database names in your Vuex store or even define them globally via plugins to be used throughout your application.