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 clientPromis…


This content originally appeared on DEV Community and was authored by ivkeMilioner

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 }
  }
}


This content originally appeared on DEV Community and was authored by ivkeMilioner


Print Share Comment Cite Upload Translate Updates
APA

ivkeMilioner | Sciencx (2022-04-29T16:44:48+00:00) How to dynamically change collection in from client side ?. Retrieved from https://www.scien.cx/2022/04/29/how-to-dynamically-change-collection-in-from-client-side/

MLA
" » How to dynamically change collection in from client side ?." ivkeMilioner | Sciencx - Friday April 29, 2022, https://www.scien.cx/2022/04/29/how-to-dynamically-change-collection-in-from-client-side/
HARVARD
ivkeMilioner | Sciencx Friday April 29, 2022 » How to dynamically change collection in from client side ?., viewed ,<https://www.scien.cx/2022/04/29/how-to-dynamically-change-collection-in-from-client-side/>
VANCOUVER
ivkeMilioner | Sciencx - » How to dynamically change collection in from client side ?. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/04/29/how-to-dynamically-change-collection-in-from-client-side/
CHICAGO
" » How to dynamically change collection in from client side ?." ivkeMilioner | Sciencx - Accessed . https://www.scien.cx/2022/04/29/how-to-dynamically-change-collection-in-from-client-side/
IEEE
" » How to dynamically change collection in from client side ?." ivkeMilioner | Sciencx [Online]. Available: https://www.scien.cx/2022/04/29/how-to-dynamically-change-collection-in-from-client-side/. [Accessed: ]
rf:citation
» How to dynamically change collection in from client side ? | ivkeMilioner | Sciencx | https://www.scien.cx/2022/04/29/how-to-dynamically-change-collection-in-from-client-side/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.