mongodb is so confusing!

646 views
Skip to first unread message

Frank Z

unread,
Apr 8, 2014, 8:10:27 PM4/8/14
to nod...@googlegroups.com
I installed mongodb through my unbuntu terminal after installing node.js.

When I run sudo service mongodb start

I get back "start: Job is already running: mongodb" from the terminal

So my assumption is that everything is running properly here...

I'm trying to make this todo list from an example in my book, using express.js. I used the package.json file to install the depenencies:

{
  "name": "application-name",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node app.js"
  },
  "dependencies": {
    "express": "3.5.1",
    "jade": "*",
    "mongoose":"3.8.4"
  }
}

Then I run npm install in my terminal...

Everything is correct in my app.js file, all the variables declared properly with mongoose and everything...

I run node app.js and get back:

/home/frankz/Desktop/nodesandbox/connect_to_mongo/app.js:40
app.get('/users', user.list);
                  ^
ReferenceError: user is not defined
    at Object.<anonymous> (/home/frankz/Desktop/nodesandbox/connect_to_mongo/app.js:40:19)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3

So what's going on here? 

Jose Luis Rivas

unread,
Apr 8, 2014, 8:20:32 PM4/8/14
to nod...@googlegroups.com
Where's "user"?

You have to write and declare "user" before using it. It has nothing to
do with mongodb, at all.

You have to write the method "list" inside user too before trying to tie
something to that method.
> --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> ---
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to nodejs+un...@googlegroups.com
> <mailto:nodejs+un...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

--
Jose Luis Rivas - http://joseluisrivas.net
Venezuela - GPG: 0xB9AC8C43

Martín Ciparelli

unread,
Apr 8, 2014, 8:26:04 PM4/8/14
to nod...@googlegroups.com
You don't know Javascript and because of that mongodb is confusing?
Inline image 1


To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.

Frank Z

unread,
Apr 8, 2014, 11:29:04 PM4/8/14
to nod...@googlegroups.com, mcipa...@gmail.com
I know JavaScript, as a front end programmer. I'm not a back end programmer.

Frank Z

unread,
Apr 8, 2014, 11:29:41 PM4/8/14
to nod...@googlegroups.com
hmmmm I'll look into this "user" business...

Frank Z

unread,
Apr 8, 2014, 11:36:21 PM4/8/14
to nod...@googlegroups.com, mcipa...@gmail.com
By the way... What is your deal exactly? What makes you assume that I don't know JavaScript? I'm guessing you're bitter because you're still a virgin? I understand bro, it's cool.

You are better at JavaScript at least, so good for you.

On Tuesday, April 8, 2014 8:26:04 PM UTC-4, Martín Ciparelli wrote:

Conrad Pankoff

unread,
Apr 8, 2014, 11:38:12 PM4/8/14
to nod...@googlegroups.com
This isn't related to MongoDB at all.

1) Paste code
2) ???
3) Profit!

Adam Brady

unread,
Apr 8, 2014, 11:40:06 PM4/8/14
to nod...@googlegroups.com, mcipa...@gmail.com
Hollyyyyyy shit, I hope your future (and current) employers find these and decide to fire you.

Luiz Filipe

unread,
Apr 8, 2014, 11:39:18 PM4/8/14
to nod...@googlegroups.com

Focus guys this list is destined to share knowledge about nodejs.

Frank Z

unread,
Apr 8, 2014, 11:40:04 PM4/8/14
to nod...@googlegroups.com
Huh?


--
--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

---
You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/XF9mhLAGepQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.

Conrad Pankoff

unread,
Apr 8, 2014, 11:41:49 PM4/8/14
to nod...@googlegroups.com, mcipa...@gmail.com
wow, dude. Just wow.

Frank Z

unread,
Apr 8, 2014, 11:43:31 PM4/8/14
to nod...@googlegroups.com
Can someone actually help me? YES, I am VERY GOOD at JavaScript. 

Here's the deal, I'm NEW TO BACK END!!!!!!!!!!!!!!!!!!

I'm better with very direct and lower level stuff like, you know, actual programming, making variables and loops and what not.. This is all layers of abstractions upon abstractions, Dependencies piled on top of dependencies... 

Why does mongoDB require mongoose? Why does it need a user declared? How to I get Mongo to talk to Express.js? This exceed the boundaries of JavaScript as a programming language.


You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/XF9mhLAGepQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.

Luiz Filipe

unread,
Apr 8, 2014, 11:44:27 PM4/8/14
to nod...@googlegroups.com

Is just a undefined variable the guy is learning nodejs, is natural in the learning curve confusing apples with bananas...

Frank Z

unread,
Apr 8, 2014, 11:46:19 PM4/8/14
to nod...@googlegroups.com
Thank you Luiz, you're cool. 

Some of these other guys have a chip on their shoulders because they think they are superior to everyone else. You're cool. I'm still learning the difference between bananas and apples! They don't understand that.


You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/XF9mhLAGepQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.

Adam Brady

unread,
Apr 8, 2014, 11:48:12 PM4/8/14
to nod...@googlegroups.com
I actually lol'd.

What language are we using then? Please enlighten us.

Frank Z

unread,
Apr 8, 2014, 11:49:34 PM4/8/14
to nod...@googlegroups.com
JavaScript? Right? That's what I use.

Conrad Pankoff

unread,
Apr 8, 2014, 11:51:13 PM4/8/14
to nod...@googlegroups.com

Frank Z

unread,
Apr 8, 2014, 11:51:54 PM4/8/14
to nod...@googlegroups.com
Let me clarify this... I normally use JavaScript on the front end. I've made a lot of progress with Node.js (in my opinion) but a lot of it is so nebulous... Even using a terminal was very alien to me until like a few weeks ago. I'm so used to just using text editors with files in folders on windows. 

Frank Z

unread,
Apr 8, 2014, 11:53:46 PM4/8/14
to nod...@googlegroups.com
Hahahahaha.

This isn't fair.... I didn't even realize that was the problem.

Adam Brady

unread,
Apr 8, 2014, 11:53:58 PM4/8/14
to nod...@googlegroups.com
But according to you "This exceed the boundaries of JavaScript as a programming language."

And with that logic, we can't be using Javascript.

Jose Luis Rivas

unread,
Apr 8, 2014, 11:54:30 PM4/8/14
to nod...@googlegroups.com
It does not require mongoose. You can use the native mongodb driver
installed with `npm install mongodb` and require it with `mongodb =
require('mongodb')`.

It does not requires a user being declared. You could have put your
method right away but that's kind of messy. Something like:

app.get('/users', function (req, res, next) {
// Your operations go here
});

As you can see that's pure JavaScript and user was supposed to be an
Object with the methods for users-related actions.

On 4/8/14, 10:43 PM, Frank Z wrote:
> Can someone actually help me? YES, I am VERY GOOD at JavaScript.
>
> Here's the deal, I'm NEW TO BACK END!!!!!!!!!!!!!!!!!!
>
> I'm better with very direct and lower level stuff like, you know, actual
> programming, making variables and loops and what not.. This is all
> layers of abstractions upon abstractions, Dependencies piled on top of
> dependencies...
>
> Why does mongoDB require mongoose? Why does it need a user declared? How
> to I get Mongo to talk to Express.js? This exceed the boundaries of
> JavaScript as a programming language.
>
>
> On Tue, Apr 8, 2014 at 11:39 PM, Luiz Filipe <luizfi...@gmail.com
> <mailto:luizfi...@gmail.com>> wrote:
>
> Focus guys this list is destined to share knowledge about nodejs.
>
> Em 09/04/2014 00:36, "Frank Z" <fran...@gmail.com
> <mailto:fran...@gmail.com>> escreveu:
>
> By the way... What is your deal exactly? What makes you assume
> that I don't know JavaScript? I'm guessing you're bitter because
> you're still a virgin? I understand bro, it's cool.
>
> You are better at JavaScript at least, so good for you.
>
> On Tuesday, April 8, 2014 8:26:04 PM UTC-4, Martín Ciparelli wrote:
>
> You don't know Javascript and because of that mongodb is
> confusing?
> /home/frankz/Desktop/__nodesandbox/connect_to_mongo/__app.js:40
> > app.get('/users', user.list);
> > ^
> > ReferenceError: user is not defined
> > at Object.<anonymous>
> >
> (/home/frankz/Desktop/__nodesandbox/connect_to_mongo/__app.js:40:19)
> > at Module._compile (module.js:456:26)
> > at Object.Module._extensions..js (module.js:474:10)
> > at Module.load (module.js:356:32)
> > at Function.Module._load (module.js:312:12)
> > at Function.Module.runMain (module.js:497:10)
> > at startup (node.js:119:16)
> > at node.js:902:3
> >
> > So what's going on here?
> >
> > --
> > --
> > Job Board: http://jobs.nodejs.org/
> > Posting guidelines:
> >
> https://github.com/joyent/__node/wiki/Mailing-List-__Posting-Guidelines
> <https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines>
> > You received this message because you are subscribed
> to the Google
> > Groups "nodejs" group.
> > To post to this group, send email to
> nod...@googlegroups.com
> > To unsubscribe from this group, send email to
> > nodejs+un...@__googlegroups.com
> > For more options, visit this group at
> > http://groups.google.com/__group/nodejs?hl=en?hl=en
> <http://groups.google.com/group/nodejs?hl=en?hl=en>
> >
> > ---
> > You received this message because you are subscribed
> to the Google
> > Groups "nodejs" group.
> > To unsubscribe from this group and stop receiving
> emails from it, send
> > an email to nodejs+un...@__googlegroups.com
> > <mailto:nodejs+un...@__googlegroups.com>.
> > For more options, visit
> https://groups.google.com/d/__optout
> <https://groups.google.com/d/optout>.
>
> --
> Jose Luis Rivas - http://joseluisrivas.net
> Venezuela - GPG: 0xB9AC8C43
>
> --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/__node/wiki/Mailing-List-__Posting-Guidelines
> <https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines>
> You received this message because you are subscribed to
> the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> To unsubscribe from this group, send email to
> nodejs+un...@__googlegroups.com
> For more options, visit this group at
> http://groups.google.com/__group/nodejs?hl=en?hl=en
> <http://groups.google.com/group/nodejs?hl=en?hl=en>
>
> ---
> You received this message because you are subscribed to
> the Google Groups "nodejs" group.
> To unsubscribe from this group and stop receiving emails
> from it, send an email to nodejs+un...@__googlegroups.com.
> For more options, visit
> https://groups.google.com/d/__optout
> <https://groups.google.com/d/optout>.
>
>
> --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> <mailto:nod...@googlegroups.com>
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> <mailto:nodejs%2Bunsu...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> ---
> You received this message because you are subscribed to the
> Google Groups "nodejs" group.
> To unsubscribe from this group and stop receiving emails from
> it, send an email to nodejs+un...@googlegroups.com
> <mailto:nodejs+un...@googlegroups.com>.
>
> For more options, visit https://groups.google.com/d/optout.
>
> --
> --
> Job Board: http://jobs.nodejs.org/
> Posting guidelines:
> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
> You received this message because you are subscribed to the Google
> Groups "nodejs" group.
> To post to this group, send email to nod...@googlegroups.com
> <mailto:nod...@googlegroups.com>
> To unsubscribe from this group, send email to
> nodejs+un...@googlegroups.com
> <mailto:nodejs%2Bunsu...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/nodejs?hl=en?hl=en
>
> ---
> You received this message because you are subscribed to a topic in
> the Google Groups "nodejs" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/nodejs/XF9mhLAGepQ/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to

Conrad Pankoff

unread,
Apr 9, 2014, 12:02:37 AM4/9/14
to nod...@googlegroups.com
Just to clarify, nobody has a problem with you learning. The node community (of which I consider myself a part) loves teaching people and helping people to learn more about node or JavaScript in general.

The problem that people (again, including me) have with you is your attitude. You came into this with the typical bravado and false confidence of so many before you who've been ridiculed. "Everything is correct in my app.js file" is a predeclaration of your correctness and infallibility, when every sign points directly to your code being the problem. That's just an example. After people reacted in similar fashion (i.e. somewhat rudely), you launched into an idiotic attack of character ("I'm guessing you're bitter because you're still a virgin"). This is just another example. I'm not saying that these two things alone are the reason that people have been a jerk (back) to you, but just that they're particularly good examples of the overall attitude you display.

Just so you know, I'm going to post more image macros every time I see you being a jerk. In that regard, I have a bit of credit saved up from the last thread, so I'll use it to post this one.

John Teague

unread,
Apr 9, 2014, 12:05:48 AM4/9/14
to nod...@googlegroups.com
Can everyone please dial it back a bit or at least keep it off the list.

Frank, if you post your code or put it in a gist, a lot of people will be happy to help.

Keep Calm and Node On.

Adam Brady

unread,
Apr 9, 2014, 12:08:46 AM4/9/14
to nod...@googlegroups.com
You.... did.. read through the thread, right? This isn't the first thread this has happened in - and when we try to explain things, he starts throwing around insults. 

Frank Z

unread,
Apr 9, 2014, 12:18:48 AM4/9/14
to nod...@googlegroups.com
I don't know anymore. I joined this group partly because I wanted to learn Node.js, but I also knew that other places weren't particularly helpful. I have a lot of pent up frustration from all these times when I searched for answers on the internet, and saw nothing but people answering my questions, and other people's questions, with nothing but links to documentation (and literally nothing more), without really helping anyone.

And so I came here and found the same crap. And it's like, "what the hell..."

Now here's where I get confused.. I find that when working with Node.js, and these particular modules for back end, there are a large number of predefined variables, which makes sense! But I have a tendency to over analyze them I suppose.

But you've won. I'll leave.

Luiz Filipe

unread,
Apr 9, 2014, 12:20:50 AM4/9/14
to nod...@googlegroups.com

But the question is... why are you feeling insulted? Just see that guy is angry because he did not understand something. I did not saying that he is right. Im trying to explain that you have to keep the mind free of feelings when you try explain or help an angry person. That will helps you to not begin an unconstrutive conversation gets longer.

Christopher Mina

unread,
Apr 9, 2014, 12:31:11 AM4/9/14
to nod...@googlegroups.com
Frank,

All the other crap aside, hopefully by now you have figured out the issue.  However, I'll try to be a little more crystal clear than what has been posted already. 

You've got a couple issues, starting at the beginning:

1) You're correct, mongod process is already running, so you're good there.
2) It sounds like you may have copy / pasted code from an Express.js tutorial.  A good first place would always be to fully understand what is going on with every line of code when running through a tutorial.  Usually there is a line-by-line guide or some sort of documentation to walk you through it.
3) You're Express app configuration file is fine, as you said, you ran npm install against package.json and all worked well.  Good.
4) Now we come to the meat of the problem, when the express app is starting, it does a bunch of things defined in app.js, including setting up your Express routes.  This is line that reads: "app.get('/users', user.list);"   What this says is "When user navigates to http://{myapp.com}/users, invoke the function "list" on the object "user".  User.list (function) is your callback to that URL route.

In Node, as in javascript in general and any other language, you must define something before invoking it. 
I'm sure you understand this part perfectly well.  However, assuming you read the error carefully, you'll notice it says: "ReferenceError: user is not defined".  This should look identical to errors you have seen in client side code before.  What it says is that you are attempting to reference an object (user) that does not exist.  Without seeing your code, its difficult to determine why this doesn't exist.  However, there are some very common things to know about Node, one of which is how to "include" another JS file.  Assuming you had another file named "User.js", and within that was a "class" function or object literal, and within that was a method called "list", then you would reference that with as:

var user = require("path/to/models/User.js");

So long as this was done above the declaration of the route, it would all work.  Another option would be if the "user" was declared inline.  For instance, it might look like:

var user = function() {
};

user.list = function() {
};

Or better yet, "list" would be applied to the prototype:  user.prototype.list = function() { };

Any of these cases, so long as they are defined or referenced above the ("/users", user.list), would cause your app to run.


Regarding Mongoose, it is absolutely not required.  You can use the native Javascript driver for mongodb just fine (http://docs.mongodb.org/ecosystem/drivers/javascript/), or any of several other libraries (e.g. Mongoskin).  However, it seems like your tutorial is using mongoose, as it simplifies things just to get started.  So you should stick with that.

Regarding Mongodb in general, hopefully by now it is clear that your null reference error has nothing to do with Mongo or its setup.

Frank Z

unread,
Apr 9, 2014, 12:37:30 AM4/9/14
to nod...@googlegroups.com
Christopher, you are the man! Thank you! 


Note to moderators, Conrad Pankoff bills himself as a "Professional Cyber Bully" : http://webcache.googleusercontent.com/search?q=cache:GvjFQCWny-AJ:about.me/deoxxa+&cd=12&hl=en&ct=clnk&gl=us




--

Martín Ciparelli

unread,
Apr 9, 2014, 12:39:55 AM4/9/14
to nod...@googlegroups.com

Sorry Frank if I did sound a little bit mean, it wasn't my intention. I just assumed that you don't know the language because you posted one line of code that makes use of two Javascript variables and an error that tells you there is one of them that is not defined and as a result your subject was: "mongodb is so confusing!".
As you may know from others already:
- your variable user is not defined
- mongo is running fine
- mongo has nothing to do with a Javascript variable being undefined
- you can check out in github some libraries for using mongodb from node that will help you get along with it
- my virginity is a private variable

You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.

Joshua Holbrook

unread,
Apr 9, 2014, 12:40:33 AM4/9/14
to nod...@googlegroups.com
> Conrad Pankoff bills himself as a "Professional Cyber Bully"

I sure HOPE so! Otherwise, wth are we paying him for??

--Josh

Frank Z

unread,
Apr 9, 2014, 12:43:34 AM4/9/14
to nod...@googlegroups.com
Haha, no worries man. I apologize for that. 


On Wed, Apr 9, 2014 at 12:39 AM, Martín Ciparelli <mcipa...@gmail.com> wrote:
You received this message because you are subscribed to a topic in the Google Groups "nodejs" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/nodejs/XF9mhLAGepQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to nodejs+un...@googlegroups.com.

Oleg Verych

unread,
Apr 9, 2014, 8:04:20 AM4/9/14
to nod...@googlegroups.com
It does not require mongoose. You can use the native mongodb driver
installed with `npm install mongodb` and require it with `mongodb =
require('mongodb')`.

It does not requires a user being declared. You could have put your
method right away but that's kind of messy. Something like:

app.get('/users', function (req, res, next) {
  // Your operations go here
});

As you can see that's pure JavaScript and user was supposed to be an
Object with the methods for users-related actions.

I'd recomend smooth front-to-backend node.js + mongodb transaction via
this Guide: "ExtJS Editable Grid + Node.js"

Good luck, Frank.
________

Reply all
Reply to author
Forward
0 new messages