https://github.com/bipul-hossein/mongodb_crud_operations
Here is the MongoDB crude operation done in a simple way. Which is done step by step to make it easy to understand. And here are some simple examples.
https://github.com/bipul-hossein/mongodb_crud_operations
database javascipt mongodb nodejs react
Last synced: 3 months ago
JSON representation
Here is the MongoDB crude operation done in a simple way. Which is done step by step to make it easy to understand. And here are some simple examples.
- Host: GitHub
- URL: https://github.com/bipul-hossein/mongodb_crud_operations
- Owner: bipul-hossein
- Created: 2022-11-06T19:21:41.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-01T19:05:57.000Z (almost 3 years ago)
- Last Synced: 2025-01-22T06:32:55.256Z (over 1 year ago)
- Topics: database, javascipt, mongodb, nodejs, react
- Language: JavaScript
- Homepage:
- Size: 322 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
#### Go To- src > Pages > Home > Home.js
// Get requests
```ruby
useEffect(() => {
fetch('http://localhost:5000/users')
.then(res => res.json())
.then(data => setUsers(data))
}, [])
```
// POST example
// step_1. create a post Api in Server site
// step_2. uploading json data with method,headers,body; like this-
/* ----------See the exam. in mozilla doc-------------- */
```ruby
fetch('http://localhost:5000/users', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(user),
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
const newUsers = [...users, data];
setUsers(newUsers)
})
.catch(error => {
console.error('Error:', error);
});
//server site
// step_4 receive req with(req.body);
// step_5 stop undefine data use middle ware (app.use(express.json());)
event.target.reset()
}
```
// DELETE
```ruby
const handleDelete = user => {
const agree = window.confirm(`you want to delete${user.name}`)
if (agree) {
// console.log(`you want to delete${user._id}`)
fetch(`http://localhost:5000/users/${user._id}`, {
method: 'DELETE',
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
if (data.deletedCount > 0) {
alert('User delete successfully')
const remainingUsers = users.filter(usr => usr._id !== user._id)
setUsers(remainingUsers)
}
})
.catch(error => {
console.error('Error:', error);
});
}
}
```