Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get result from users.find() function #29

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

get result from users.find() function #29

profesoralex opened this issue Aug 30, 2011 · 0 comments

Comments

@profesoralex
Copy link

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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant