Skip to content

Code example from the Developing a Real-time Dashboard with FastAPI, MongoDB, and WebSockets blog post by Abdulazeez Abdulazeez Adeshina

Notifications You must be signed in to change notification settings

tyndyll/fastapi-mongodb-realtime-dashboard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Developing a Real-time Dashboard with FastAPI, MongoDB, and WebSockets

Code example from the Developing a Real-time Dashboard with FastAPI, MongoDB, and WebSockets blog post by Abdulazeez Abdulazeez Adeshina

## Mongo Calls

For real-time updates on the backend, we're going to make use of MongoDB Change Streams.

MongoDB Change Streams let you listen to real-time changes in your collections without polling (sending frequent request to an endpoint for updates).

Enabling a Replica Set

$ mongod --replSet rs0 --port 27017 --dbpath /data/db

Initiate the Replica Set

$ mongosh orders

> rs.initiate()
> db.createCollection("orders", {changeStreamPreAndPostImages: { enabled: true }})

Calls

# Create
curl -X POST http://localhost:8000/api/orders \
-H "Content-Type: application/json" \
-d '{"item": "FastAPI Course By TestDriven", "customer": "Abdulazeez Abdulazeez Adeshina"}'

# Update
curl -X PUT http://localhost:8000/api/orders/6858134ea4a6a24ed2af4afa \
  -H "Content-Type: application/json" \
  -d '{"status": "completed"}'

# Delete
curl -X DELETE http://localhost:8000/api/orders/6858134ea4a6a24ed2af4afa

About

Code example from the Developing a Real-time Dashboard with FastAPI, MongoDB, and WebSockets blog post by Abdulazeez Abdulazeez Adeshina

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published