Simple CRUD operations in ReactJS for local database

I have a VERY csmple application. For reasons relates to reactJS rencer cycles I need to store the page name when the user clicks a tile in the Navbar. I have a local MongoDB installation on my Mac ( Catalina ) and I need to know how to specify the database in a reactJS module (require? import? etc) and then how to (in reactJS):

a) count the records in the db (there should only be 0 or 1)
b) add a text field to the first record is the count is 0
v) replace the first record is the count is 1

I do not use Express - there is no html except in the divs exported from each component.

There is a great deal of information on complex usages, but I can find nothing on these simple operations.

Hi @Stephen_Jones welcome to the community.

I’m not sure if there’s a React to MongoDB interface, seeing as MongoDB is a server-side technology and React is a client-side technology. Typically in a MERN stack (MongoDB Express React Node), there is a REST API layer using Node that lets the client communicate with the database using something like AJAX.

Since MongoDB by itself does not provide a native REST interface, people typically uses Express+Node, but this can be replaced with many alternatives, such as Django (Python), or Spring (Java).

See The Modern Application Stack – Part 1: Introducing The MEAN Stack for some examples.

Alternatively depending on your goals & use case, you may be able to use MongoDB Realm. See Introduction to MongoDB Realm for Web Developers for more details.

Best regards,
Kevin

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.