When performing a mail merge using document forms, the function DocsList.getFileById(copyId).getAs("application/pdf") converts the temporary document to PDF.
How can I save the PDF to a document collection immediately after sending the attached PDF via e-mail?
Related
I'm trying to implement pdf upload with express and save it to mongo db . But it was only saving to localy my pc i can't send it to mongo db. Can any one help me how can i upload or access pdf files using multer or any other library.
As far as I know, you have 2 -maybe 3- ways of using "files" with MongoDB, the approach will depend on your use case (and size of the document):
Store the files directly in the document
As you know you can store anything you want in a JSON/BSON document, you just need to store the bytes and your PDF will be part of the document.
You just need to be careful about the document size limit of 16Mb.
You can add meta-data for the file in the JSON document, and they are stored in the same place.
For example in Java you will just store byte[] in an attribute, look at his test:
https://github.com/mongodb/mongo-java-driver/blob/master/src/test/com/mongodb/ByteTest.java#L188
Use GridFS
GridFS allows you to store files of "any size" into MongoDB. The file you are storing is divided in chunks by the driver and stored into smaller documents into MongoDB, when you read it it will be put back in a single file. With this approach, you do not have any size limit.
In this case, if you want to add metadata, you create a JSON document that you store with all the attributes and a reference to the GridFS file.
You can find information about this here: http://docs.mongodb.org/manual/core/gridfs/
and to this Java test:
https://github.com/mongodb/mongo-java-driver/blob/master/src/test/com/mongodb/gridfs/GridFSTest.java
Create Reference to an external storage
This one is not directly a "MongoDB" use case, but I think it is important to mention it. You can obviously store the files in some special storage and use MongoDB just for the metadata and reference this file. I will take a stupid example but suppose you want to create a Video application, you can store the videos in YouTube and reference this into the document with all your application metadata.
So let's stay on your use case/question, so you can use approaches 1 & 2, and it will depend on the size of the files and how do you access them. If you can give us more information about your application people may have a stronger opinion on the best approach.
If you are looking for people doing this, you can look at this presentation from MongoDB World: http://www.mongodb.com/presentations/translational-medicine-platform-sanofi-0
We have a document which has 50k records.
We are trying to edit a particular record from the document but when we do it the whole documents gets overwritten.
How can we edit a record from the document without losing all the data from the same document?
I am trying to insert a document into mongodb using apache NiFi. I want to insert a document just from Flow File attributes but not the Flow File content.
I have tried using PutMongo processor but it insert the content of the Flow file which I don't want it to insert. I need to insert a custom document by using the flow file's attributes.
You can use a processor like AttributesToJson, or ReplaceText, to overwrite the flow file content with the attributes that you want to use for the Mongo document.
You can use Jolt JSON for customizing or limit your attribute.
https://jolt-demo.appspot.com/#inception
Says I'm building a blog system. So for a blog post, the user will be able to write text and upload media file. Here's the flow behind :
an insert query is created when user click new post.
with that id it can save the blog content, both text and uploaded media.
the problem with this approach is many empty table record have to be deleted to optimize my db. I need to use this approach as I'm using nosql db (mongodb), so the media files' name have to have blog post id as references.
Most database drivers for MongoDB allow you to generate ObjectIDs on the client-side. If you set the _id field of a document to such a generated ObjectID, MongoDB will use it instead of one generated on the database. This allows you to create a group of referencing documents on the application-side and then insert them all at once.
However, it might be more appropriate in your use-case to embed all the sub-documents in the blog-post-document and store it all in the database as one document.
I am now using perl script client to store some big data into mongoDB .But now I met a problem ,some document exceeds the size limit of 16M,so ,I have to choose GridFS.From the GridFS document ,I read this:
GridFS is a specification for storing and retrieving files that exceed the BSON-document size limit of 16MB.
Instead of storing a file in a single document, GridFS divides a file into parts, or chunks, [1] and stores each of those chunks as a separate document. By default GridFS limits chunk size to 256k.
It really make me confused.What does it mean by "file"?"Instead of storing a file in a single document",it means , mongoDB stores a file in a single document without using GridFS,right ?But I think it should say:"Instead of storing a document in a single file,...".So ,the relationship and difference between "file" and "document" make me confused.
What does it mean by "file"?
A file. A word document, Excel spreadsheet, HTML file anything that is a file. GridFS is designed for file storage.
it means , mongoDB stores a file in a single document
MongoDB does not do anything, it does not even manage GridFS, the documentation assumes you come to GridFS after encountering the limited size of a single document, as you have.
Instead of storing a document in a single file,...
Nope, that is incorrect. What is a document? MongoDBs own records are called documents, how can you store those within files in the database? You store data within documents in the database.
So ,the relationship and difference between "file" and "document" make me confused.
File is a physical file and a document is basically a row.