gridform icon indicating copy to clipboard operation
gridform copied to clipboard

GridFS + Mongoose

Open CodersBrothers opened this issue 11 years ago • 5 comments

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

CodersBrothers avatar May 07 '13 09:05 CodersBrothers

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

aheckmann avatar May 07 '13 16:05 aheckmann

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 avatar May 08 '13 11:05 CodersBrothers

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 avatar May 08 '13 12:05 CodersBrothers

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

CodersBrothers avatar May 08 '13 15:05 CodersBrothers

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

MForMarlon avatar Mar 13 '15 16:03 MForMarlon