Meteor: how can I seed a FS Collection?

189 Views Asked by At

I'm trying to insert images in a FS Collection, using the file path only, and retrieving the generated ID every time. I do it like this in the server:

FS.debug = true;

Meteor.startup(function () {
    var id = ImagesPublications.insert('angelina.jpg');
});

But when i do it i get the following errors in the console:

I20150621-10:01:10.418(2)? FS.HTTP.unmount:   
I20150621-10:01:10.419(2)? {}
I20150621-10:01:10.420(2)? Registered HTTP method URLs:
I20150621-10:01:10.420(2)? /cfs/files/:collectionName/:id/:filename
I20150621-10:01:10.420(2)? /cfs/files/:collectionName/:id
I20150621-10:01:10.420(2)? /cfs/files/:collectionName
W20150621-10:01:10.456(2)? (STDERR) 
W20150621-10:01:10.457(2)? (STDERR) /root/.meteor/packages/meteor-tool/.1.1.3.2gp1mq++os.linux.x86_32+web.browser+web.cordova/mt-os.linux.x86_32/dev_bundle/server-lib/node_modules/fibers/future.js:278
W20150621-10:01:10.457(2)? (STDERR)                         throw(ex);
W20150621-10:01:10.458(2)? (STDERR)                               ^
W20150621-10:01:10.461(2)? (STDERR) Error: ENOENT, stat 'angelina.jpg'
W20150621-10:01:10.461(2)? (STDERR)   at Object.Future.wait (/root/.meteor/packages/meteor-tool/.1.1.3.2gp1mq++os.linux.x86_32+web.browser+web.cordova/mt-os.linux.x86_32/dev_bundle/server-lib/node_modules/fibers/future.js:398:15)
W20150621-10:01:10.461(2)? (STDERR)   at /media/DATOS/Ivan/Escritorio/DAW/Mercadillo virtual/Exchanger/app/.meteor/local/build/programs/server/packages/meteor.js:174:24
W20150621-10:01:10.461(2)? (STDERR)   at DataMan.dataManSize [as size] (/media/DATOS/Ivan/Escritorio/DAW/Mercadillo virtual/Exchanger/app/.meteor/local/build/programs/server/packages/cfs_data-man.js:157:103)
W20150621-10:01:10.462(2)? (STDERR)   at setData (/media/DATOS/Ivan/Escritorio/DAW/Mercadillo virtual/Exchanger/app/.meteor/local/build/programs/server/packages/cfs_file.js:145:29)
W20150621-10:01:10.462(2)? (STDERR)   at EventEmitter.fsFileAttachData [as attachData] (/media/DATOS/Ivan/Escritorio/DAW/Mercadillo virtual/Exchanger/app/.meteor/local/build/programs/server/packages/cfs_file.js:120:5)
W20150621-10:01:10.462(2)? (STDERR)   at EventEmitter.FS.File (/media/DATOS/Ivan/Escritorio/DAW/Mercadillo virtual/Exchanger/app/.meteor/local/build/programs/server/packages/cfs_file.js:43:10)
W20150621-10:01:10.462(2)? (STDERR)   at EventEmitter.FS.Collection.insert (/media/DATOS/Ivan/Escritorio/DAW/Mercadillo virtual/Exchanger/app/.meteor/local/build/programs/server/packages/cfs_collection.js:282:19)
W20150621-10:01:10.462(2)? (STDERR)   at app/server/bootstrap.js:4:32
W20150621-10:01:10.462(2)? (STDERR)   at /media/DATOS/Ivan/Escritorio/DAW/Mercadillo virtual/Exchanger/app/.meteor/local/build/programs/server/boot.js:229:5
W20150621-10:01:10.462(2)? (STDERR) 
W20150621-10:01:10.462(2)? (STDERR)     - - - - -
W20150621-10:01:10.462(2)? (STDERR) 
W20150621-10:01:10.462(2)? (STDERR) 

Note: I'm using Meteor 1.1.0.2 and all the packages are up to date.

1

There are 1 best solutions below

0
On

Ok, I figured the problem. The path of the file is not valid, so I need to use the full path to make it work. I also need to get the id in the callback, since insert doesn't return the inserted id.

Meteor.startup(function () {

    var id;

    ImagesPublications.insert(process.env.PWD + '/server/angelina.jpg', function(err, obj) {
        id = obj._id;
    });
});