Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

different database for gridfs #5

Open
Furqankhanzada opened this issue Jul 28, 2016 · 1 comment
Open

different database for gridfs #5

Furqankhanzada opened this issue Jul 28, 2016 · 1 comment

Comments

@Furqankhanzada
Copy link

I want to save images to different database instead of default one.

I have changed the collection driver and now images collection is being created on different database but not others collections that hold files.

check my code:

if(Meteor.isServer){
    var d = new MongoInternals.RemoteCollectionDriver('mongodb://test123:test123@ds029725.mlab.com:29725/test');
    Images = new Mongo.Collection('images', { _driver: d });
}else{
    Images = new Mongo.Collection('images');
}

function loggedIn(userId) {
    return !!userId;
}

Images.allow({
    insert: loggedIn,
    update: loggedIn,
    remove: loggedIn
});


ImagesStore = new UploadFS.store.GridFS({
    collection: Images,
    name: 'images',
    filter: new UploadFS.Filter({
        contentTypes: ['image/*']
    })
});

any suggestion or help ? how can i achive it ?

@jalik
Copy link
Owner

jalik commented Jul 29, 2016

Hi @Furqankhanzada I guess, you would have use the copyTo store option, do something like this :

let options = {};

if (Meteor.isServer) {
    options._driver = new MongoInternals.RemoteCollectionDriver('mongodb://test123:test123@ds029725.mlab.com:29725/test');
}
ImagesCopy = new Mongo.Collection('images', options);
Images = new Mongo.Collection('images');

function loggedIn(userId) {
    return !!userId;
}

let imageFilter = new UploadFS.Filter({
    contentTypes: ['image/*']
});

let permissions = new UploadFS.StorePermissions({
    insert: loggedIn,
    update: loggedIn,
    remove: loggedIn
});

ImagesCopyStore = new UploadFS.store.GridFS({
    collection: ImagesCopy,
    name: 'images-copy',
    filter: imageFilter
});

ImagesStore = new UploadFS.store.GridFS({
    collection: Images,
    name: 'images',
    filter: imageFilter,
    permissions: permissions,
    copyTo: [ImagesCopyStore]
});

EDIT : you cannot set several collections on one store because each store could have different data for the same file (if it has been modified for example), so each store need a different collection, you can use store like normal storage, backup storage or to save alternative version of a file (thumbnail, archive, etc), so even if you save twice the same file, it leads to 2 physical files, this is why you need two collections, one per store, I hope I am clear.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants