
Node.js, MongoDB, and you: an intro in parts - liz_mongohq
http://blog.mongohq.com/node-js-mongodb-and-you-an-intro-in-parts/
======
rubyn00bie
Nice article, quick and easy to get through and... I'm sure actually doing
this is much better than when I tried this as both have matured quite a bit
but... This article is a nightmare of mine, having to use both Nodejs and
MongoDB together.

Why? I still can't get this out of my mind:

[https://twitter.com/HackerNewsOnion/status/38257854706983731...](https://twitter.com/HackerNewsOnion/status/382578547069837312)

Also before anyone gets too serious with a reply, learn to laugh. Humility
goes along way! I poke fun at Ruby/Rails all the time.

~~~
owenversteeg
Every time I read about Mongo I think of [http://mongodb-is-web-
scale.com](http://mongodb-is-web-scale.com)

That said, if your project doesn't store extremely important data and needs to
be quick to write Mongo's an OK choice.

Of course, even though it's much easier to use than other databases at first,
if you later want to make sure your data doesn't disappear it's a total PITA.

~~~
victorhooi
I think this sort of FUD has been beaten to death...lol.

------
fourstar
Mongo is cool, and Mongoose (node ORM-like wrapper) is pretty nice as well,
but after using it for a few months on a project I was building I realized
that I was duplicating a ton of data. Until mongo solves the issue of joins
(something that is better suited to a sql solution), I just had to revert and
ended up used node-mysql which is a pretty decent node mysql driver. I was
considering using mongo for sessions (with connect-mongo), but ended up going
with redis as it's pretty solid solution (and according to some benchmarks,
faster).

~~~
twerquie
I feel you - I recently started a node project on LevelDB and ultimately
switched over to an SQL database. The difference though is I went for Postgres
9.3, which has incredible native JSON support, allowing you to slice parts of
your JSON data out as a record set, join them against tables, as well as other
crazy things like partial indexes on deeply nested JSON values which may or
may not be present.

I really think Pg is starting to blow Mongo out of the water.

~~~
hkarthik
Any suggestions on ORMs or npm packages to use with pg and node?

~~~
twerquie
I'm a big fan of ORMs in other ecosystems (Rails and Django, for example), but
in node I like to write more functional-style code, composing small modules
into larger applications.

For this, check out the fantastic node-postgres adapter from brianc as well as
his node-sql package for authoring SQL statements.

[https://github.com/brianc/node-postgres](https://github.com/brianc/node-
postgres) [https://github.com/brianc/node-sql](https://github.com/brianc/node-
sql)

------
nailer
IMPORTANT: the current stable official node-mongodb-native silently wraps
exceptions. So completely non DB related code might be failing in your app,
but because it's called in a callback, it won't ever show up.

This is acknowledged by 10gen/MongoDB inc:
[https://groups.google.com/forum/#!topic/node-mongodb-
native/...](https://groups.google.com/forum/#!topic/node-mongodb-
native/AZewJaX4YuE)

Use the beta 1.3 driver until 1.4 comes out unless you want to tear your hair
out.

------
727374
The 'pyramid of doom' is one of my pain points with node right now. The
article's solution is to push the anonymous functions out into separate named
functions, but this just adds more code. Would have been awesome to use
promises instead.

~~~
babby
All I have to say guys; promises + generators. My god, it's absolutely
delicious.

Seriously, just learn it. Get your --harmony flag on. It will be in browsers
soon enough as well. It's literally the future of javascript and having
converted some of my codebase to promises + generators instead of just
promises. Wow. It felt amazing. Suddenly everything doesn't look like
spaghetti.

I use bluebird for promises and a custom dev fork of Coffeescript that allows
for generators. You do have to wrap your anonymous functions with
"Promise.coroutine", but thats really it. You could always just not even use
promises, and go plain generators too.

~~~
727374
If I promisify some code with bluebird, can I use it with Mongoose's built in
promises? Or will promises from different libraries explode when they touch?

~~~
babby
Well promises are suppose to be compatible with one another due to adhering to
rules. Should be A-OK. Bluebird is just, at the moment, the most performant
Promise library, and they seem to be building their API as close to what
native Promises will be like. You could really use any promise library and it
wouldn't matter much, perhaps use the one that mongoose uses if it's an issue.

