How use mongoose + locomotive???

880 views
Skip to first unread message

Rodrigo Fonseca

unread,
Dec 18, 2012, 9:48:30 AM12/18/12
to locomo...@googlegroups.com
 i started this tutorial:

 and made everything... I'm getting this message:

"mongoose is not defined"

in here:

module.exports = function() { switch (this.env) { case 'development': mongoose.connect('mongodb://mongodb.example.com/dev'); break; case 'production': mongoose.connect('mongodb://mongodb.example.com/prod'); break; } mongoose.model('User', schemas.UserSchema); mongoose.model('Post', schemas.PostSchema); }


what's the problem??? I know that the object "mongoose" is not defined, but this guide don't show me how to do this and where i would do this...

Jared Hanson

unread,
Dec 18, 2012, 10:51:42 AM12/18/12
to locomo...@googlegroups.com
You'll need to:

    $ npm install mongoose

and then do the usual:

    var mongoose = require('mongoose')

in any file where you use mongoose, including the initializer.  See http://mongoosejs.com/ for more info on where to go from there.

--
Jared Hanson <http://jaredhanson.net/>

Rodrigo Fonseca

unread,
Dec 18, 2012, 10:59:13 AM12/18/12
to locomo...@googlegroups.com

 Yeah, thanks Jared, i think about to do this, but the guide said:

To use the Mongoose adapter, install it via npm:

npm install locomotive-mongoose

 So, i just do like de guide said, i think, that the guide could be more complete...
But, thanks, i will try to do this.

Jared Hanson

unread,
Dec 18, 2012, 11:00:39 AM12/18/12
to locomo...@googlegroups.com
Thanks for the feedback.  I just recently published this new set of docs.  I'll update them so they are easier to follow.

Rodrigo Fonseca

unread,
Dec 18, 2012, 11:01:06 AM12/18/12
to locomo...@googlegroups.com

 I need to install mongo db to use mongoose??
 
I installed mongdb using this comand:

 npm install mongojs

cheers



Jared Hanson

unread,
Dec 18, 2012, 11:02:51 AM12/18/12
to locomo...@googlegroups.com
MongoDB is a database server, not a Node.js module.  You'll need to download a package for your OS it and install it from: http://www.mongodb.org/

Rodrigo Fonseca

unread,
Dec 18, 2012, 11:14:58 AM12/18/12
to locomo...@googlegroups.com
Yes, i know that, i'm just confusing with node, but thanks! 
Message has been deleted
Message has been deleted
Message has been deleted
Message has been deleted

Illimar Tambek

unread,
Jan 7, 2013, 8:23:34 AM1/7/13
to locomo...@googlegroups.com
I am also following the Guide but am stuck at the next step. Here is my 02_mongoose.js file:

var mongoose = require("mongoose");

module.exports = function() {
  switch (this.env) {
    case 'development':
      mongoose.connect('mongodb://localhost/slipfeed');
      break;
    case 'production':
      mongoose.connect('mongodb://mongodb.example.com/prod');
      break;
  }

  mongoose.model('Client', schemas.ClientSchema);
}

But when I start lcm server, I get the error: ReferenceError: schemas is not defined

Where should I create the schemas object so that it is globally available? Or should I attach schemas to the global app object? ANd if so , then how?

Robert Klep

unread,
Jan 7, 2013, 5:22:54 PM1/7/13
to locomo...@googlegroups.com
You have to realise that Locomotive is really ORM-agnostic. That means that it doesn't provide any sort of scaffolding or structuring regarding models at all. That said, the example you're referring to is a bit misleading, because it seems to imply that Locomotive does.

How you set up your ORM, whether it be mongoose or something else entirely, is totally up to you. I recently made a boilerplate project to show how I used Locomotive together with Sequelize (which is an ORM for MySQL, SQLite and PostgreSQL). It's not very well documented, but the project isn't very big and hopefully quite easy to understand. Start with config/initializers/10_sequelize.js to get an idea on how to find and load schemas and how to use them throughout your application.

– robert

Op maandag 7 januari 2013 14:23:34 UTC+1 schreef Illimar Tambek het volgende:

Frederic Jacquemin

unread,
Dec 3, 2013, 9:14:03 AM12/3/13
to locomo...@googlegroups.com
Hi Jared, 
can you, please, be clearer when you write "including the initializer." ?
do you mean any Schema & Models declaration ??

I'm beginning with Locomotive & very happy with so far, and I'm trying my best to make it play with MongoDB without flooding the GoogleGroup :)
(yes, i've been through the Guide too... )
Thanks,
Frederic

Frederic Jacquemin

unread,
Dec 3, 2013, 11:12:14 AM12/3/13
to locomo...@googlegroups.com
ok, got it working.
I was confusing concepts...Model, Schema ...
Reply all
Reply to author
Forward
0 new messages