An Interest In:
Web News this Week
- March 23, 2024
- March 22, 2024
- March 21, 2024
- March 20, 2024
- March 19, 2024
- March 18, 2024
- March 17, 2024
April 29, 2022 04:44 pm GMT
Original Link: https://dev.to/ivkemilioner/how-to-dynamically-change-collection-in-from-client-side--5oa
How to dynamically change collection in from client side ?
I want to change collection from client side, but I do not have sucess.
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 }}
component
export async function getStaticProps (context) { let res1 = await fetch('http://localhost:3000/api/questionApi', { method: 'GET', headers: { 'Content-Type': 'application/json' } }) let question = await res1.json() return { props: { question } }}
Original Link: https://dev.to/ivkemilioner/how-to-dynamically-change-collection-in-from-client-side--5oa
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To