Please enable JavaScript.
Coggle requires JavaScript to display documents.
Node Js - Connect to a Database (MongoDB (CURD Operations (Read (find(),…
Node Js - Connect to a Database
MySql
MongoDB
scalable
high-performance
open source
NoSQL database
Built-in modules
mongoose
mongoose.connect('mongodb://localhost/mydb)
CURD Operations
Read
find()
findOne()
findById()
Update
update()
findOneAndUpdate()
findByIdAndUpdate()
Delete
remove()
findOneAndRemove()
findByIdAndRemove()
Create
save()
Restful Service
from Node.js
What?
REST
– Representational State Transfer
It follows web standard based
architecture
It leverages
HTTP Protocol
to the fullest
Types?
GET
=> access a resource.
POST
=> create a resource
PUT
=> update a resource.
DELETE
=> delete a resource.
Built-in node module
restler module
Methods
request(url, options
) - Make a request of any type to the server side.
get(url, options)
- Make GET request to the server side.
post(url, options)
- Make POST request to the server side.
put(url, options)
- Make PUT request to the server side.
del(url, options)
- Make DELETE request to the server side.
Events
complete
: function(result, response) : emitted when the request gets completed irrespective of whether it is successful or not.
success
: function(data, response) : emitted when the request is successful.
error
: function(err, response) : emitted when some error occurs.