more info on .search arguments and filter strings

This commit is contained in:
Hugo Dozois 2014-06-24 23:36:54 -04:00
parent b49c2efed2
commit 26398393ee
1 changed files with 17 additions and 9 deletions

View File

@ -187,12 +187,14 @@ defaults for you so that if you pass nothing in, it's pretty much equivalent
to an HTTP GET operation (i.e., base search against the DN, filter set to to an HTTP GET operation (i.e., base search against the DN, filter set to
always match). always match).
Like every other operation, `base` is a DN string. Options has the following Like every other operation, `base` is a DN string.
Options can be a string representing a valid LDAP filter or an object containing the following
fields: fields:
||scope||One of `base`, `one`, or `sub`. Defaults to `base`.|| ||scope||One of `base`, `one`, or `sub`. Defaults to `base`.||
||filter||A string version of an LDAP filter (see below), or a programatically constructed `Filter` object. Defaults to `(objectclass=*)`.|| ||filter||A string version of an LDAP filter (see below), or a programatically constructed `Filter` object. Defaults to `(objectclass=*)`.||
||attributes||attributes to select and return (if these are set, the server will return *only* these attributes). Defaults to the empty set, which means all attributes.|| ||attributes||attributes to select and return (if these are set, the server will return *only* these attributes). Defaults to the empty set, which means all attributes. You can provide a string if you want a single attribute or an array of string for one or many.||
||attrsOnly||boolean on whether you want the server to only return the names of the attributes, and not their values. Borderline useless. Defaults to false.|| ||attrsOnly||boolean on whether you want the server to only return the names of the attributes, and not their values. Borderline useless. Defaults to false.||
||sizeLimit||the maximum number of entries to return. Defaults to 0 (unlimited).|| ||sizeLimit||the maximum number of entries to return. Defaults to 0 (unlimited).||
||timeLimit||the maximum amount of time the server should take in responding, in seconds. Defaults to 10. Lots of servers will ignore this.|| ||timeLimit||the maximum amount of time the server should take in responding, in seconds. Defaults to 10. Lots of servers will ignore this.||
@ -211,7 +213,8 @@ Example:
var opts = { var opts = {
filter: '(&(l=Seattle)(email=*@foo.com))', filter: '(&(l=Seattle)(email=*@foo.com))',
scope: 'sub' scope: 'sub',
attributes: ['dn', 'sn', 'cn']
}; };
client.search('o=example', opts, function(err, res) { client.search('o=example', opts, function(err, res) {
@ -247,18 +250,23 @@ for an attribute `email` with a value of `foo@bar.com`. The syntax would be:
(email=foo@bar.com) (email=foo@bar.com)
ldapjs requires all filters to be surrounded by '()' blocks. Ok, that was easy. ldapjs requires all filters to be surrounded by '()' blocks. Ok, that was easy.
Let's now assume you want to find all records where the email is actually just Let's now assume that you want to find all records where the email is actually just
anything in the "@bar.com" domain, and the location attribute is set to Seattle: anything in the "@bar.com" domain and the location attribute is set to Seattle:
(&(email=*@bar.com)(l=Seattle)) (&(email=*@bar.com)(l=Seattle))
Now our filter is actually three LDAP filters. We have an `and` filter, Now our filter is actually three LDAP filters. We have an `and` filter (single
an `equality` filter (the l=Seattle), and a `substring` filter. Substrings are amp `&`), an `equality` filter `(the l=Seattle)`, and a `substring` filter.
wildcard filters. Now, let's say we want to also set our filter to include a Substrings are wildcard filters. They use `*` as the wildcard. You can put more
specification that either the employeeType *not* be a manager or a secretary: than one wildcard for a given string. For example you could do `(email=*@*bar.com)`
to match any email of @bar.com or its subdomains like "example@foo.bar.com".
Now, let's say we also want to set our filter to include a
specification that either the employeeType *not* be a manager nor a secretary:
(&(email=*@bar.com)(l=Seattle)(!(|(employeeType=manager)(employeeType=secretary)))) (&(email=*@bar.com)(l=Seattle)(!(|(employeeType=manager)(employeeType=secretary))))
The `not` character is represented as a `!`, the `or` as a single pipe `|`.
It gets a little bit complicated, but it's actually quite powerful, and lets you It gets a little bit complicated, but it's actually quite powerful, and lets you
find almost anything you're looking for. find almost anything you're looking for.