aheckmann / gridform

Stream formidable uploads into MongoDB GridFS
http://aheckmann.github.com/gridform/
MIT License
59 stars 17 forks source link

GridFS + Mongoose #5

Open CodersBrothers opened 11 years ago

CodersBrothers commented 11 years ago

Its possible use with "Mongoose", instead of "mongo" module? Thanks.

aheckmann commented 11 years ago

Yes. Mongoose uses the mongodb module. Instructions for accessing it are here: https://github.com/aheckmann/gridfs-stream#using-with-mongoose

On Tuesday, May 7, 2013, Coders Brothers wrote:

Its possible use with "Mongoose", instead of "mongo" module? Thanks.

— Reply to this email directly or view it on GitHubhttps://github.com/aheckmann/gridform/issues/5 .

Aaron @aaronheckmann https://twitter.com/#!/aaronheckmann

CodersBrothers commented 11 years ago

Im really new with mongoose and mongo in NodeJS, i cant connect, because seems i need put a model and i cant get collection reference :(

CodersBrothers commented 11 years ago

My code, but dont work, upload dont return nothing.

var express = require('express'),
     http = require('http'),
     path = require('path'),

     formidable = require('formidable'),
     gridform = require('gridform'),
     mongoose = require('mongoose'),
     Grid = require('gridfs-stream');

    var conn = mongoose.createConnection('mongodb://' + database.server + ':' + database.port + '/'  + database.name);
   conn.once('open', function(err){
    if(!err){
        console.log('Conectado a Mongo!!');
    }else{
        throw err;
    }
});

// Upload
app.post('/upload', function(req, res){

    gridform.db    = conn.db,
    gridform.mongo = mongoose.mongo;    

    var form = gridform();  

    //console.log(form);

    form.parse(req, function(err, fields, files) {

        console.log("File ID:" + files.text.id);
        res.end("File ID:" + files.text.id);

    });

});
CodersBrothers commented 11 years ago

Imposible, i cant run Express + mongoose + gridform. :(, this is my script http://paste2.org/C2sKGNG3 (I cant save, i cant get)

MForMarlon commented 9 years ago

@CodersBrothers Did you try putting the gridform.db and gridform.mongo lines inside the conn.once callback?