querying MongoDb with nodejs

I have a situation here. I have a ajax call which is used to query a value and return. in the Js file I gave like this

function getLoginData(){
    debugger;
    var getUserName=$("#inputUserName").val();
    $.ajax({
        url:'/users/loginValidation',
        dataType:'json',
        data:{"uName":getUserName},
        type:'post',
        async:false,
        success:function(data){
            debugger;
        }
    })
} 

In the Users.js file in routes I gave like this

router.post('/loginValidation',function(req,res){
    var db=req.db;
    var getName=req.body.uName;
    db.collection("Users").find({"name":getName},{"type":{$in: [ "admin", "owner" ]}}).toArray(function(err,result){
        res.json(result);
    })

})
  1. My requirement is I want to check in Users collection containing the name as in "getName" variable
  2. Along With that i want to check whether that name is of type "admin" or "owner".
  3. If both these conditions don't satisfy then return a error message

My user Collection is like this

{ "_id" : 1, "name" : "Rohith", "type" : "admin" }
{ "_id" : 2, "name" : "Kumar", "type" : "owner" }
{ "_id" : 3, "name" : "Krishna", "type" : "Sales" }
{ "_id" : 4, "name" : "Nikhil", "type" : "Sales" }
{ "_id" : 5, "name" : "Don", "type" : "admin" }

Now i am getting a null value in success of ajax call... Thanks

Use $and, like this:

db.collection("Users")
    .find({"$and": [
        {"name": getName},
        {"type": {"$in": [ "admin", "owner" ]}
    ]})
    .toArray(function(err,result){
        if (!err && !result) err = 'No results';
        if (err) return res.send(500, err);
        res.json(result);
    })