Multiple datasources

I work with two DB. One is mySQL and the other is MongoDB. Is it possible to connect prisma to both or do I need to do mongo separately and mySQL with prisma? Dont ask why, I´am new and will adapt in the beginning...
2 Replies
oscarthroedsson
oscarthroedsson6mo ago
Wondering if I can use something like this:
const mongoDB = new PrismaClient({
datasourceUrl: 'MONGO uri',
})
const mongoDB = new PrismaClient({
datasourceUrl: 'MONGO uri',
})
I am also wondering how the connection with DB and collection goes with prisma. I am doing old fashion right now. But they use prisma for mySQL and i thought it would be better to use prisma for both, it we can.
import mongoose from "mongoose"; //connects to DB
import { MongoClient } from "mongodb";
//process.env.API_KEY

const uri = process.env.MONGO_URL;
const databaseName = process.env.MONGO_DB_NAME;
const collectionName = process.env.MONGO_COLLECTION;

console.log("🔗 URI: ", uri);
console.log("DB NAME: ", databaseName);
console.log("DB NAME: ", collectionName);

const client = new MongoClient(uri);
const database = client.db(databaseName);

const connectToDatabase = async () => {
try {
await mongoose.connect(uri);
console.log("🍃 | Successfully connected to MongoDB. 🎉");
} catch (error) {
console.error("🧹 | Could not connect to MongoDB: ", error);
}
};
connectToDatabase();

export function mongoDBstring() {
const wholeColl = client.db(databaseName).collection(collectionName);
return wholeColl;
}
import mongoose from "mongoose"; //connects to DB
import { MongoClient } from "mongodb";
//process.env.API_KEY

const uri = process.env.MONGO_URL;
const databaseName = process.env.MONGO_DB_NAME;
const collectionName = process.env.MONGO_COLLECTION;

console.log("🔗 URI: ", uri);
console.log("DB NAME: ", databaseName);
console.log("DB NAME: ", collectionName);

const client = new MongoClient(uri);
const database = client.db(databaseName);

const connectToDatabase = async () => {
try {
await mongoose.connect(uri);
console.log("🍃 | Successfully connected to MongoDB. 🎉");
} catch (error) {
console.error("🧹 | Could not connect to MongoDB: ", error);
}
};
connectToDatabase();

export function mongoDBstring() {
const wholeColl = client.db(databaseName).collection(collectionName);
return wholeColl;
}
Unknown User
Unknown User6mo ago
Message Not Public
Sign In & Join Server To View
Want results from more Discord servers?
Add your server