MongoDB Express Nodes
Create Database Connection
We can't import everywhere mongoConnect as it is a kamur process so to avoid it we add it globally
1) Add ver name _db
2) Assign it to client.db()
3) create a fn and export it
Now to add db we need to just add above function
and keep server like this
Since we have already got the date we can directly add this to add all elemnet
Now to fetch the products
1) find() provides a cursor which go one by one and if there are miillion of product it will go like that
2) to array converts those product in a list
3) dont use toFind() if u have million of products...instead use pagination
Fethcing a single product
2) However,Mongodb cursor is unaware that I only want to find a single product so it will keep on goin down
3) To stop this use next() and then
But we have a error because no productId matches but it is false...the reason is that _id is not a string but specail mongodb object so to filter that Id we need to import id and use objectId method to find the specific product
m
Comments
Post a Comment