DEV Community

ivkeMilioner
ivkeMilioner

Posted on • Edited on

1

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)

AWS Security LIVE!

Join us for AWS Security LIVE!

Discover the future of cloud security. Tune in live for trends, tips, and solutions from AWS and AWS Partners.

Learn More