gridfs

How to chain write stream, immediately with a read stream in Node.js 0.10?

有些话、适合烂在心里 提交于 2019-11-29 06:14:43
The following line will download an image file from a specified url variable: var filename = path.join(__dirname, url.replace(/^.*[\\\/]/, '')); request(url).pipe(fs.createWriteStream(filename)); And these lines will take that image and save to MongoDB GridFS: var gfs = Grid(mongoose.connection.db, mongoose.mongo); var writestream = gfs.createWriteStream({ filename: filename }); fs.createReadStream(filename).pipe(writestream); Chaining pipe like this throws Error: 500 Cannot Pipe. Not Pipeable. request(url).pipe(fs.createWriteStream(filename)).pipe(writestream); This happens because the image

Querying MongoDB GridFS?

安稳与你 提交于 2019-11-29 02:14:13
I have a blogging system that stores uploaded files into the GridFS system. Problem is, I dont understand how to query it! I am using Mongoose with NodeJS which doesnt yet support GridFS so I am using the actual mongodb module for the GridFS operations. There doesn't SEEM to be a way to query the files metadata like you do documents in a regular collection. Would it be wise to store the metadata in a document pointing to the GridFS objectId? to easily be able to query? Any help would be GREATLY appreciated, im kinda stuck :/ GridFS works by storing a number of chunks for each file. This way,

MongoDB as file storage

吃可爱长大的小学妹 提交于 2019-11-28 18:46:05
i'm trying to find the best solution to create scalable storage for big files. File size can vary from 1-2 megabytes and up to 500-600 gigabytes. I have found some information about Hadoop and it's HDFS, but it looks a little bit complicated, because i don't need any Map/Reduce jobs and many other features. Now i'm thinking to use MongoDB and it's GridFS as file storage solution. And now the questions: What will happen with gridfs when i try to write few files concurrently. Will there be any lock for read/write operations? (I will use it only as file storage) Will files from gridfs be cached

mongoDB--GridFS简介

你离开我真会死。 提交于 2019-11-28 10:39:53
前言 :GridFS从名字来看,就明白是一个文件系统,它是mongodb的一个子模块,使用GridFS可以基于mongodb来持久存储文件.并且支持分布式应用(文件分布存储和读取). 使用场景:如果你的系统有如下情景 1) 有大量的上传图片(用户上传或者系统本身的文件发布等) 2) 文件的量级处于飞速增长,有可能打到单机操作系统自己的文件系统的查询性能瓶颈,甚至超过单机硬盘的扩容范围. 3) 文件的备份(不适用gridfs这种三方也可以做,但是不尽方便),文件系统访问的故障转移和修复.. 4) 文件的索引,存储除文件本身以外还需要关联更多的元数据信息(比如,不仅仅存储文件,还要保存一些文件的发布式作者/发布时间/文件tag属性等等自定义信息)并且需要索引的... 5) 基于4),对文件的分类模糊,如果采用操作系统的文件系统,文件夹分类关系混乱或者无法分类时.. 6) 当前系统是基于web的,对图片的访问根据url了规则路由的..(普通文件系统也可以) 7) 文件尺寸较小,而且众多,且文件有可能被迁移/删除等.. GridFS和其他分布式文件系统相比,并没有什么特殊的地方....如果有,那就是它和mongodb有一腿... GridFS是mongodb中用户存储大对象的工具,对于mongodb,BSON格式的数据(文档)存储有尺寸限制,最大为16M.但是在实际系统开发中

基于GridFS+NGinx构建分布式文件系统 之实战(三)

好久不见. 提交于 2019-11-28 10:39:31
基于GridFS构建分布式文件系统 首先看看什么是GridFS: GridFS is a mechanism for storing large binary files in MongoDB. There are several reasons why you might consider using GridFS for file storage: • Using GridFS can simplify your stack. If you’re already using MongoDB, GridFS obviates the need for a separate file storage architecture. • GridFS will leverage any existing replication or autosharding that you’ve set up for MongoDB, so getting failover and scale-out for file storage is easy. • GridFS can alleviate some of the issues that certain filesystems can exhibit when being used to store user uploads. For

Problem with MongoDB GridFS Saving Files with Node.JS

倾然丶 夕夏残阳落幕 提交于 2019-11-28 10:35:05
I have a function saving a file to gridfs. It somehow stopped working sporadically after a refactor and I've spent over 2 hours staring blankly at it. I swear it's roughly the same as it was. I seem to remember it not working at first before I added close, then it started working, but it could be the insomnia. Essentially the issue is the db.fs.files collection doesn't have any records, but chunks are getting added to db.fs.chunks. data is a buffer loaded from disk via fs.readFile() 31 var gs = new mongodb.GridStore(this.db, filename, "w", { 32 "chunk_size": 1024*4, 33 metadata: { 34 hashpath

Storing some small (under 1MB) files with MongoDB in NodeJS WITHOUT GridFS

前提是你 提交于 2019-11-28 05:24:18
I run a website that runs on a backend of nodeJS + mongoDB. Right now, I'm implementing a system to store some icons (small image files) that will need to be in the database. From my understanding, it makes more sense NOT to use GridFS, since that seems to be tailored for either large files or large numbers of files. Since every file that I need to save will be well under the BSON maximum file size, I should be able to save them directly into a regular document. I have 2 questions: 1) Is my reasoning correct? Is it ok to save image files within a regular mongo collection, as opposed to with

Meteor: uploading file from client to Mongo collection vs file system vs GridFS

妖精的绣舞 提交于 2019-11-27 16:58:21
Meteor is great but it lacks native supports for traditional file uploading. There are several options to handle file uploading: From the client , data can be sent using: Meteor.call('saveFile',data) or collection.insert({file:data}) 'POST' form or HTTP.call('POST') In the server , the file can be saved to: a mongodb file collection by collection.insert({file:data}) file system in /path/to/dir mongodb GridFS What are the pros and cons for these methods and how best to implement them? I am aware that there are also other options such as saving to a third party site and obtain an url. You can

Querying MongoDB GridFS?

徘徊边缘 提交于 2019-11-27 16:29:19
问题 I have a blogging system that stores uploaded files into the GridFS system. Problem is, I dont understand how to query it! I am using Mongoose with NodeJS which doesnt yet support GridFS so I am using the actual mongodb module for the GridFS operations. There doesn't SEEM to be a way to query the files metadata like you do documents in a regular collection. Would it be wise to store the metadata in a document pointing to the GridFS objectId? to easily be able to query? Any help would be