https://github.com/bserdar/blobstore
Binary object storage for MongoDB, replacement for gridfs with transaction support
https://github.com/bserdar/blobstore
go golang gridfs mongodb
Last synced: about 1 month ago
JSON representation
Binary object storage for MongoDB, replacement for gridfs with transaction support
- Host: GitHub
- URL: https://github.com/bserdar/blobstore
- Owner: bserdar
- License: apache-2.0
- Created: 2023-03-26T19:27:51.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2023-03-26T20:22:47.000Z (about 3 years ago)
- Last Synced: 2025-01-25T21:27:21.613Z (over 1 year ago)
- Topics: go, golang, gridfs, mongodb
- Language: Go
- Homepage:
- Size: 9.77 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Blobstore for MongoDB
This is intended to be a simple replacement for binary object storage
in MongoDB. GridFS does not play well with transactions, and it looks
too much like a file system so using it for generic BLOB storage is
usually inconvenient. This Go library provides a simple replacement
for it.
Create a blob store using:
``` go
store := &blobstore.Store {
Collection: coll,
}
```
Make sure indexes are created for the store. This will run once for
the lifetime of the store.
``` go
store.EnsureIndex(context.Background())
```
You can simple write to a BLOB with its id. You have to generate an ID yourself:
``` go
err := store.Write(context.Background(), blobID, bytes.NewReader(data))
```
And read from it:
``` go
rd, err := store.Read(context.Background(), blobID)
```
You have to close the returned reader. You can close it midway if you
are not interested in the whole stream.