[QUESTION] How I can use FastAPI with MongoDB libraries?
See original GitHub issueFirst check
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
Description
How can I use MongoDB using libraries such a pymongo or MongoEngine?
I tried to create a basic project with pymongo, but when I try to return MongoDB entity using .find_one()
for example, I got an error that ... ObjectId does not iterable...
.
Then I tried MongoEngine, but when I return for example Article.objects
, it just returns "_cls": ""
.
Is it possible to use MongoDB in FastAPI or I can use only SQLAlchemy?
Additional context
I also found similar issues in a repo and some answers on StackOverflow but doesn’t found how to return MongoDB entities in fastapi responses.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
How to use FastAPI with MongoDB - Python in Plain English
Integrate FastAPI with MongoDB is easier than it looks. Here you're going to see ... FastAPI uses the Pydantic library to check the...
Read more >Building a CRUD App with FastAPI and MongoDB
In this tutorial, you'll learn how to develop an asynchronous API with FastAPI and MongoDB. We'll be using the Motor package to interact...
Read more >Getting Started with MongoDB and FastAPI
MongoDB stores data as BSON. FastAPI encodes and decodes data as JSON strings. BSON has support for additional non-JSON-native data types, ...
Read more >69. FastAPI and MongoDB - YouTube
FastAPI Authentication Example With OAuth2, JSON Web Tokens and Tortoise ORM · FAST and MODERN Python API with FastAPI | FastAPI tutorial.
Read more >Benchmarking FastAPI and MongoDB Options - Medium
When it comes to Python, MongoDB and FastAPI, you have two main options: PyMongo, the official Python driver for MongoDB, or Motor, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Have you tried using the json utils described above https://api.mongodb.com/python/current/api/bson/json_util.html I truly think that’s the solution to your problem. You need a serializer that understands mongo objects, that serializer does.
Thanks for the help here everyone! 👏 🙇
I assume you solved your problem, so thanks for reporting back and closing the issue @KirillSaltykov 👍