I have a react website that should query data from my mongodb atlas database and display it to the user. In my atlas cluster, I already created a user readuser
with the password readuser
and readall-permissions.
Following the official guide, I try this:
import React from 'react';
import MongoClient from 'mongodb';
function App() {
var uri = "mongodb+srv://readuser:readuser@personalwebsite-oerah.mongodb.net/test?retryWrites=true&w=majority";
var client = new MongoClient(uri, {useNewUrlParser : true});
client.connect(err => {
console.log(err);
client.close();
});
return (<p>Hello world</p>);
}
export default App;
However, react displays the error Uncaught TypeError: Cannot read property 'replace' of undefined at matchesParentDomain (uri_parser.js:24)
- Is the node js solution fitting for my problem? (It seems to be intended more for backend applications)
- Is it possible to make my database publicly readable to avoid needing to login from my app?
- How do I fix the error?
I know this sounds very similar to this thread, but I don't use mongoose, so the problem is a little different.