You are not logged in.
How to save a File to MongoDB with mORMot Framework?
I Use TMongoClient to link MongoDB like sample in Documentation. But the Sample don't tell me how to save a Pictrue , file or stream to MongoDB.
Could You tell how to do? and get it back.
----------------------------------------------
here is the Sample.
---------------------------------------------
var Coll: TMongoCollection;
doc: variant;
i: integer;
begin
Coll := DB.CollectionOrCreate[COLL_NAME];
TDocVariant.New(doc);
for i := 1 to 10 do
begin
doc.Clear;
doc.Name := 'Name '+IntToStr(i+1);
doc.Number := i;
Coll.Save(doc);
writeln('Inserted with _id=',doc._id);
end;
end;
-----------------------------
http://synopse.info/files/html/Synopse% … #TITLE_187
Offline
For complex BLOB types, you should better use a TBsonVariant instead of a TDocVariant.
Our BSON variant is able to store BLOB kind of fields.
But there is no GridFS support yet.
So you have the limitation of 16 MB of size per document.
If you want to store huge content, do not use MongoDB, but a regular file system over the network.
Offline
thinks !
Offline
In fact, the easiest may be to use a TDocVariant to create the document, and then use BsonVariantType.FromBinary() to generate a BLOB value:
var Coll: TMongoCollection;
doc,blob: variant;
i: integer;
begin
Coll := DB.CollectionOrCreate[COLL_NAME];
TDocVariant.New(doc);
for i := 1 to 10 do
begin
doc.Clear;
doc.Name := 'Name '+IntToStr(i+1);
doc.Number := i;
BsonVariantType.FromBinary(StringFromFile(PathFolder+doc.Name),bbtGeneric,blob);
doc.FileContent := blob;
Coll.Save(doc);
writeln('Inserted with _id=',doc._id);
end;
end;
The limit of 16 MB size for the whole document (including the blob) still applies.
Offline
mORMot Can Save MongoDB GridFS ? how to do ?
Offline
can you plan to support ? tks !
Offline
Offline
+1 for GridFS please
Offline
What are the difficults to support GridFS? Aside from that, who programmed it.
Offline
We do not need GridFS here at all - since our blobs are smaller than the 16 MB limit.
And we have some doubts about its practical impact with our ORM/ODM, which usually contain all its data in memory during process, so the 16 MB limit seems fair enough.
Big files benefit from using a dedicated distributed file system (like Hadoop, or even ZFS), and not MongoDB GridFS, which is IMHO a half-backed feature: you store huge binary in the middle of collections...
See https://www.compose.io/articles/gridfs- … -and-cons/
This is why the feature is not implemented yet.
There are no technical difficulty at SynMongoDB.pas level.
Just missing time to add this feature.
Any patch is welcome!
Offline
thank you @ab, for your explanations. I would have to check that again. But I think we exceed the 16 MB limit also not. And the files are rarely changed.
Offline