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).
$ mongod --replSet rs0 --port 27017 --dbpath /data/db$ mongosh orders
> rs.initiate()
> db.createCollection("orders", {changeStreamPreAndPostImages: { enabled: true }})
# 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