search in Ldap.js

I am trying to use search method of Ldap.js in my node.js code. But it doesn't work. Here it is my code :

searchFunc : function (){
            console.log('inside search');
            client.bind('cn=Manager,dc=foo,dc=com', kredito231, function(err) {
                if (err) {
                    console.log(err);
                    client.unbind();
                    return;
                }

                var opts = {
                    filter: (('Email=*@foo.com'))
                } ;
                 //This search works correct:
                //client.search( 'cn=x,ou=users' + ',' + 'dc=foo,dc=com', function(err,res){
                //This one doesn't work. But everything is done according api
                client.search('dc=foo,dc=com', opts, function(err, res) {
                    res.on('searchEntry', function(entry) {
                        console.log('hit');
                        console.log('entry: ' + JSON.stringify(entry.object));
                    });
                    res.on('searchReference', function(referral) {
                        console.log('referral: ' + referral.uris.join());
                    });
                    res.on('error', function(err) {
                        console.log('searchFailed') ;
                        console.error('error: ' + err.message);
                    });
                    res.on('end', function(result) {
                        console.log('4') ;
                        console.log('status: ' + result.status);
                    });
                });

            });

        }

When I user search method by using dn name , it returns the correct object with it,s attributes. ( res.on('searchEntry', function(entry) part is executed . because it can find the record in Ldap). But when I use client.search('dc=foo,dc=com', opts, function(err, res) with opt defined above , it always go to the branch 4 : res.on('end', function(result) and never returns error. status is 0 . here is the api documentation of Ldap : http://ldapjs.org/client.html

This does not work for dc=foo,dc=com because that entry in the LDAP directory does not have the attribute Email and hence your filter does not match. The entry 'cn=x,ou=users,dc=foo,dc=com' in LDAP directory probably has this attribute which is why it works.