socket.io returns [object Object] from mongojs query

I've started looking at socket.io and some MongoDB with mongojs.

Summary: Client doesn't send data to server through socket.io so mongojs doesn't have anything to look for and just returns first document in collection, I'd like it to return null or false so I can take appropriate action. Any help appreciated, very new to node.js and this.

I need a log in function, but when I click the link I've made to log in this should run from the client:

    <script>
        var socket = io.connect('http://localhost:13163');

        socket.on('connect', function () {
            socket.emit(console.log('Client connected'));
        });
        socket.on('queryResponse', function (res, err) {
            if (res == "[object Object]") {
                console.log('EMPTY OBJ SERVER: ' + res + ' ' + err);
            }
            else{
                console.log('IF NOT EXEC' + res[0].email)
            }
        });
        //socket.send('client hello');
        //pageload
        $(function () {
            $('#login').click(function () {
                var username = $('#username').val();
                var password = $('#password').val();
                if (!username || !password) {
                    event.preventDefault();
                    console.log('Need data in both fields');
                }
                else {
                    event.preventDefault();
                    socket.emit('querydata', function (username, password) {
                        console.log("CLIENT: Querying server for data...");
                    });
                }
            });
        });
    </script>

This should send the username and password to the server which should then run this:

socket.on('querydata', function (user_username, user_password) {
    db.users.find({email: user_username, pass: user_password}, function (err, docs) {
        if (err || !docs) {
            socket.emit('queryResponse', 'No users found', err);
            console.log('if - ' + docs[0].email);
        }
        else {
            socket.emit('queryResponse', docs);
            console.log('else - ' + docs[0].email + 'user_password' + user_password + 'user_username' + user_username);
        }
    });
});

What's weird about this is that, it finds only the first document of the collection. I've just found out that the 'user_username' and 'user_password' overloads are undefined, is this just some retarded mistake from my side?

You are doing it wrong. In a first look, i see couple of mistakes in your code. The first one here

if (res == "[object Object]") 

You can not control response content in that way. You probably see [object Object] string in your javascript debugger. You have to do this comparison according to the server response as a json data. If it will lead you a trouble you can use JSON.parse(response).

The second one, you do not send username and password to the server actually. You have to use

socket.emit('querydata', { username: username, password: password }, function (data) {
   // Server Ack here
}

instead of

socket.emit('querydata', function (username, password) ...

And try this

socket.emit('queryResponse', {err: 'No User Found'});

instad of

socket.emit('queryResponse', 'No User Found', err);

And in your client check the response as

if(response.hasOwnProperty('err')) / /Handle error

In you client side queryResponse listener, try this;

socket.on('queryResponse', function (res) {
        if(res.hasOwnProperty('err')) / Handle Error
        else // You have an array in `res`
    });