"CORS" issue with MongoDB

Hi Hi, Does anyone know how to get rid of the "CORS" with MongoDB?
I think my function is correct as it works when I disable the "cross-origin restrictions" from safari.

Here is my function:

var myHeaders = new Headers(); myHeaders.append("Content-Type", "application/json"); myHeaders.append("Access-Control-Allow-Headers", "*"); myHeaders.append( "api-key", "xxxxxxxxxxxx" ); var raw = JSON.stringify({ dataSource: "hackett-db-cluster", database: "FirstDB", collection: "FirstDB", document: { username: userName, date: formattedDate, address: userAddress, email: userEmailText, active: "true", }, }); var requestOptions = { method: "POST", headers: myHeaders, body: raw, redirect: "follow", }; fetch( "https://ap-southeast-1.aws.data.mongodb-api.com/app/data-dxseo/endpoint/data/v1/action/insertOne", requestOptions ) .then((response) => response.text()) .then((result) => { console.log(result); }) .catch((error) => { console.log("An error occurred: ", error); });
CleanShot_2023-12-15_at_15.42.44.png
CleanShot_2023-12-15_at_16.07.58.png
CleanShot_2023-12-15_at_16.08.49.png
Was this page helpful?