DEV Community

ivkeMilioner
ivkeMilioner

Posted on

I get err MongoInvalidArgumentError: Collection name must be a String

I get err MongoInvalidArgumentError: Collection name must be a String

First function:

export default function Questions ({data})
 {const [collection, setCollection] = useState("")
Enter fullscreen mode Exit fullscreen mode

Second function:

export async function getServerSideProps({collection} ) 
{const client = await clientPromise;const db = client.db("javascript_questions");

let data = await db.collection(collection).find({}).toArray();
data = JSON.parse(JSON.stringify(data));
return {props: { data },  };}
Enter fullscreen mode Exit fullscreen mode

Discussion (0)