Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

get result from users.find() function #29

Open
profesoralex opened this Issue · 0 comments

1 participant

@profesoralex

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
Something went wrong with that request. Please try again.