I’ve googled and also read he documents here on Mongodb. Can someone show me an example of attaching a binary file in a Mongo record?
Been searching and trying for weeks.
I’ve googled and also read he documents here on Mongodb. Can someone show me an example of attaching a binary file in a Mongo record?
Been searching and trying for weeks.
Hello @Harry_Melamed … You want the Grid File System feature of MongoDB.
Do I need the grid system for small files. Under 2 MB?
Also a code example of the post. Python preferred.
You might as well use the grid file system if you’re storing opaque objects in MongoDB.
MongoDB’s AI expert will write you a very nice example in Python!
Anyway, here’s a simple example. Of course change the URI and filename to suit.
from pymongo import MongoClient
import gridfs
client = MongoClient("mongodb+srv://myid:mYpAsSw0rD@cluster0-foo.mongodb.net")
db = client.test
bucket = gridfs.GridFSBucket(db)
with open("myfile.txt", "rb") as f:
bucket.upload_from_stream("myfile", f)
client.close()
Topic | Replies | Views | Activity |
---|---|---|---|
MongoDB Entity Framework - DB Transactions Support | 1 | 516 | Jul 2024 |
What is columnar index? | 4 | 894 | Jul 2024 |
Darshan Hiranandani : How can I retrieve information on documents that were inserted within the last 2 or 3 days on a standalone server? | 1 | 157 | Aug 2024 |
Unexpected query behavior in sharded database | 1 | 44 | Nov 2024 |
Does exists any Mongo design patterns to be able to make all forms and datagrids totally dynamic? | 5 | 50 | Feb 14 |