DEV Community

ivkeMilioner
ivkeMilioner

Posted on • Edited on

I want to dynamically change collections, but I do not know how to pass "colletions" from components.

I want to dynamically change collections, but I do not know how to pass "colletions" from components.

import clientPromise from "../../lib/mongodb2";
export default async function handler(req, res ) {
const collection = req.query.collection;
const client = await clientPromise;
const db2 = client.db("javascript_questions");
switch (req.method) {
case "GET":
const question = await db2.collection(collection).find({}).toArray();
res.json(question);
break;
}
}

Top comments (0)