Query, edit and store CSV files using JSP and MongoDB

356 views
Skip to first unread message

Shi Yu

unread,
Jan 5, 2011, 8:24:31 PM1/5/11
to mongod...@googlegroups.com
Hi Mongoers,

I have been using MongoDB for as large databases to store <key,value> and interact with Map/Reduce. It works just fine. Now I need to setup a website for project evaluation. The web is written in JSP(Java Server Pages), and we want to use MongoDB to store plain text files in CSV (line by line, column by tab) format. The web user should be able to retrieve the stored files and download them to their browser. They might edit/update those files and commit them back to MongoDB through JSP.

First of all, is this scenario doable with MongoDB?
Second, is there any existing paper or tutorial explaining this process? Certainly I will start conceiving the implementation details but if someone could provide some hints that would be very helpful.

Cheers,

Shi


Scott Hernandez

unread,
Jan 5, 2011, 8:52:49 PM1/5/11
to mongod...@googlegroups.com
You could use GridFS: http://mongodb.org/display/DOCS/GridFS

> --
> You received this message because you are subscribed to the Google Groups
> "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to
> mongodb-user...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/mongodb-user?hl=en.
>

Keith Branton

unread,
Jan 5, 2011, 8:55:56 PM1/5/11
to mongod...@googlegroups.com
It's pretty easy to do this with java and mongo. 

First you need to decide if a normal document will always be big enough. The current document limit is 4MB, and will soon be increased to 16MB when 1.8 is released. If you think you may ever need bigger documents than that then GridFS may be a good option.

I use this approach for photo sharing, but it would work for serving any type of file from mongo (or any source).

You will need to use a multipart post for upload - extract the file and store in mongo.

In order to download a file, like a csv file, it needs to have a url. You can then have an <a> tag pointing at the url on your web page, and if everything is set up correctly clicking the link will initiate a download.

These document urls should be mapped to a servlet in web.xml. The servlet should use the request parameters to work out which document to fetch, then set the content type, length, headers, etag etc as appropriate and write the document to the response.getOutputStream(). If you want to store various types of documents (i.e. more than just csv) you can also associate metadata, such as mime-type with the document.

Hope this helps.

Keith.


Shi Yu

unread,
Jan 5, 2011, 8:59:42 PM1/5/11
to mongod...@googlegroups.com
Many thanks to Scott and Keith for their suggestions. They sound very nice, which will be very useful to my design.

Cheers,

Shi
   
 
       
 
 
Reply all
Reply to author
Forward
0 new messages