get result from users.find() function #29

Open
profesoralex opened this Issue Aug 30, 2011 · 0 comments

Comments

Projects
None yet
1 participant

Hi!
I have the code:

var sys = require('sys');
var nStore = require('nstore/lib/nstore').extend(require('nstore/lib/nstore/query')());
var users = nStore.new('data/users.db', function (){
users.find({user: "alex", pass:"123"}, (function(err, results) {
if(err) {
sys.puts('not found...');
}
else
{
sys.puts(results.creationix.room);
}
}));
});

What I need is something like:

var sys = require('sys');
function routeToRoom(userId,passw){
var roomId=0;
var nStore = require('nstore/lib/nstore').extend(require('nstore/lib/nstore/query')());
var users = nStore.new('data/users.db', function (){
users.find({user: userId, pass:passw}, (function(err, results) {
if(err) {
roomId=-1;
}
else
{
roomId=results.creationix.room;
}
}));
});
return roomId;
}
sys.puts(routeToRoom("alex","123"));

But I get always: 0

I guess "return roomId;" is executed before that " roomId=results.creationix.room;" . Could someone help me whit this code?
Thanks in advance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment