Live data from Hacker News

Nodejs and MongoDB, A Beginner's Approach

blog.ksetyadi.com

1–10 of 34 posts

Re: Nodejs and MongoDB, A Beginner's Approach

#5
post #4

I'm both Node and MongoDB user and like them, but this can get really messy when there's a chain of callbacks involved, eg when you need a sequence of results but want to do it in a asynchronous fashion.

Is that specific to MongoDB on node, or is that just generally true of node.js code though?

Re: Nodejs and MongoDB, A Beginner's Approach

#6
This guide really shows what I think is a big problem with a lot of Node guides, they don't go beyond the first 5 minutes.

There are a ton of guides on how to set up a webserver in 20 lines, but hardly any on how to (properly) handle a lot of async callbacks and requests etc.

Re: Nodejs and MongoDB, A Beginner's Approach

#8
post #5
post #4

I'm both Node and MongoDB user and like them, but this can get really messy when there's a chain of callbacks involved, eg when you need a sequence of results but want to do it in a asynchronous fashion.

Is that specific to MongoDB on node, or is that just generally true of node.js code though?

It's generally true for Node when you have a lot of chained I/O. You can somewhat avoid it using events (so you set up event listeners instead of just chaining callbacks endlessly). So far I haven't seen any MongoDB module for Node taking advantage of those (haven't looked a lot yet, though).

Re: Nodejs and MongoDB, A Beginner's Approach

#9
post #5
post #4

I'm both Node and MongoDB user and like them, but this can get really messy when there's a chain of callbacks involved, eg when you need a sequence of results but want to do it in a asynchronous fashion.

Is that specific to MongoDB on node, or is that just generally true of node.js code though?

It's a problem with writing asynchronous code when you have lots of consecutive requests. I don't know if node has something like this but the Tornado team have written http://www.tornadoweb.org/documentation/gen.html which can make such things a little easier

Re: Nodejs and MongoDB, A Beginner's Approach

#10
post #8
post #5

Earlier quoted context omitted.

Is that specific to MongoDB on node, or is that just generally true of node.js code though?

It's generally true for Node when you have a lot of chained I/O. You can somewhat avoid it using events (so you set up event listeners instead of just chaining callbacks endlessly). So far I haven't seen any MongoDB module for Node taking advantage of those (haven't looked a lot yet, though).

Using event instead of callback to sequentially get the results with asynchronous way it's a potentially good idea. I also haven't learn much about another Nodejs-MongoDB libraries except the one what I have mentioned there. Please share if you have a follow-up on this technique.
Post reply on HN