Live data from Hacker News

Nodejs and MongoDB, A Beginner's Approach

blog.ksetyadi.com

11–20 of 34 posts

Re: Nodejs and MongoDB, A Beginner's Approach

#11
post #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.

It's hard to cover many aspects of it when we talked about getting our feet wet. I try to include as few terms as possible that potentially confused people to start coding Nodejs-MongoDB. It's probably a big problem when you try to get your feet wet on the first day you learn about swimming just by jumping all over the pool. But then, hopefully, we learn.

Thanks for your opinion :)

Re: Nodejs and MongoDB, A Beginner's Approach

#14
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.

I've been using this:

https://github.com/creationix/step

While I wouldn't quite call it pretty, it keeps things at the same indentation level, and I can still use closures to maintain the illusion of a single "thread".

Re: Nodejs and MongoDB, A Beginner's Approach

#15
post #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.

I've written about how to use callbacks in this context: http://denis.papathanasiou.org/?p=704

Re: Nodejs and MongoDB, A Beginner's Approach

#16
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).

I've used EventEmitter on a couple toy projects, but I've always assumed that's adding a bit more overhead to everything than just using callbacks. It's easier to read though and probably easier for someone else to figure out in the future. I've played with node.js libraries that have callbacks strung out over several files, so tracking down exactly where some behavior is happening isn't easy.

There are a few examples out there about using events/listeners, but I think there's room for a really good one.

Re: Nodejs and MongoDB, A Beginner's Approach

#17
post #2

There's something incredibly natural about node & mongo together.

Actually it's more like: hey, let's take two tools that ought to be used with utmost caution by people who know what they're doing and why they need them, and present them as the best thing since sliced bread.

The huge majority of uses for either would be better served without them.

Re: Nodejs and MongoDB, A Beginner's Approach

#18
post #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.

Agree with this. Was disappointed the guide didn't delve into asynchronous even at a basic level. This is what makes nodejs and mongodb worth using and I don't think the concepts are overly difficult to grasp.

Re: Nodejs and MongoDB, A Beginner's Approach

#20
To be honest, a good attempt by the author but I wouldn't recommend this to a beginner. Why? I don't recommend the use of the native driver - you end up with needlessly complex code.

I don't want to criticize the authors work. He's done a pretty good and thorough job. Hopefully I'll pen down an easier guide later tonight.

Post reply on HN