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 |
---|---|---|---|
Darshan Hiranandani : Has anyone tried disabling writeConcern acknowledgment to enhance performance? | 1 | 66 | Aug 2024 |
Timeseries data structure | 4 | 49 | Oct 2024 |
Why would scanning 28k documents in the 2nd stage of an aggregation take 22 seconds? | 11 | 123 | Nov 2024 |
DBException::toString(): FileRenameFailed: Access is denied\nActual exception | 2 | 105 | Nov 2024 |
UpdateOne With Upsert True and InsertOne Behavior During BulkWrite | 0 | 33 | Nov 2024 |