Node - MongoDB: collection don't find anything, using mongodb driver. Shell does return value

I've a simple code trying to find a document in a MongoDB collection. I can find it normally with the shell client of Mongo, but through Node is impossible, I've tried many ways to no avail.

First my results from MongoDB itself:

raul@rmedina:~$ mongo sdk_back
MongoDB shell version: 2.0.6
connecting to: sdk_back
> db.metadatos.find();
{ "_id" : ObjectId("514cbee35c10db0299c015c7"), "tipo" : "proceso" }
> db.metadatos.findOne({"tipo":"proceso"});
{ "_id" : ObjectId("514cbee35c10db0299c015c7"), "tipo" : "proceso" }
> db.metadatos.findOne({tipo:"proceso"});
{ "_id" : ObjectId("514cbee35c10db0299c015c7"), "tipo" : "proceso" }
> 

As you can see, both find and findOne queries works. Now this is my Node code:

    var utils   = require('../utils/utils.js'),
    Server = require('mongodb').Server,
    Db = require('mongodb').Db;

    exports.procesaJSON = function (input_json){
    if(!utils.validaJSON(input_json))
        throw new Error('JSON de entrada inválido!');

    //procesamos
    input_json = JSON.parse(input_json);

    if(typeof(input_json.id) === "undefined")
        throw new Error('JSON de entrada inválido (falta propiedad \"id\"!');

    //obtenemos meta-data de mongo
    var db = new Db("sdk_back", new Server('localhost',27017,{auto_reconnect:true, poolsize:1}),{safe:true});
    db.open(function(err,db){
        if(!err){
            db.collection("metadatos",function(err,collection){
                console.log('Entering collection meta-data');
                if(!err){
                    console.log('Lets find one');
                    collection.findOne({"tipo":"proceso"},function(err,doc){
                        console.log('Results of findOne');
                        if(!err){
                            console.log(doc);
                        }
                        else{
                            throw new Error('Error al buscar meta_data!');
                        }

                        if(doc){
                            console.log('We have results');
                        }
                        else{
                            console.log('We dont have results');
                        }
                    });
                }
                else{
                    throw new Error('Error al buscar meta_data 1!');
                }
            });
        }
        else{
            throw new Error('Error al conectarse a MongoDB!');
        }
        db.close();
    });
};

And the output is always:

raul@rmedina:~$ node pu_entrypoint.js 
Entering collection meta-data
Lets find one
raul@rmedina:~$ 

As you can see, the log with the text "Results of findOne" is never displayed, so the findOne method actually never gets executed, or something like that.

My question is, what am I doing wrong? I've droped and recreated the collection, dropped the database and even I changed my /data/db directory for Mongo, to no avail.

What am I doing wrong?

Thank you!

[SOLVED] UPDATE: The problem was with db.close(). Node beign asynchronous, reached the close of the db before reaching the find of the collections, so off course couldn't find a thing. Just moving db.close inside my last callback, solved the issue. Here is the edited code:

db.open(function(err,db){
            if(!err){
                db.collection("metadatos",function(err,collection){
                    console.log('Entering collection meta-data');
                    if(!err){
                        console.log('Lets find one');
                        collection.findOne({"tipo":"proceso"},function(err,doc){
                            console.log('Results of findOne');
                            if(!err){
                                if(doc){
                                    console.log('We have results');
                                    console.log(doc._id);
                                }
                                else{
                                    console.log('We dont have results');
                                }
/********** MOVED db.close() HERE ********************/
                                db.close();
                            }
                            else{
                                throw new Error('Error al buscar meta_data!');
                            }
                        });
                    }
                    else{
                        throw new Error('Error al buscar meta_data 1!');
                    }
                });
            }
            else{
                throw new Error('Error al conectarse a MongoDB!');
            }
/********** REMOVED db.close() FROM HERE ********************/
        });

The problem is with db.close(). Node begins asynchronous and reached the close of the db before reaching the find of the collections, so off course couldn't find a thing. Moving db.close inside the last callback, solves the issue. Here is the edited code:

    db.open(function(err,db){
        if(!err){
            db.collection("metadatos",function(err,collection){
                console.log('Entering collection meta-data');
                if(!err){
                    console.log('Lets find one');
                    collection.findOne({"tipo":"proceso"},function(err,doc){
                        console.log('Results of findOne');
                        if(!err){
                            if(doc){
                                console.log('We have results');
                                console.log(doc._id);
                            }
                            else{
                                console.log('We dont have results');
                            }
/********** MOVE db.close() HERE ********************/
                            db.close();
                        }
                        else{
                            throw new Error('Error al buscar meta_data!');
                        }
                    });
                }
                else{
                    throw new Error('Error al buscar meta_data 1!');
                }
            });
        }
        else{
            throw new Error('Error al conectarse a MongoDB!');
        }
/********** REMOVED db.close() FROM HERE ********************/
    });