How can I find users in node AD by "dn"'s chunk? - node.js

I want to search through the user and fetch them by a pattern of their Distinguish Name. My object structure is:
{"dn": "CN=Manager,OU=PH,OU=xxx HQ xxx,DC=xxx,DC=xxx",
"userPrincipalName": "user1#domain.com",
"sAMAccountName": "User1",
"whenCreated": "20190517064007.0Z",
"pwdLastSet": "0",
"userAccountControl": "512",
"sn": "User1",
"givenName": "User1",
"cn": "User1",
"displayName": "User nickname",
"groups": []}
I use this package - https://www.npmjs.com/package/activedirectory#findUsers.
Function: findUsers.
Expected result: find all users that have
"CN=Manager"
in their "dn".
I've already tried some of these queries:
dn=*CN=${managerName}*`
{dn:{filter:'*CN=${managerName}*'}}
{filter:'*CN=${managerName}*'}
{filter:{dn: '*CN=${managerName}*'}}
Every time ldap returns with an empty array or indicates an error in query

Note that dn isn't actually an attribute in Active Directory. I think you're after distinguishedName.
But you can't use wildcards in any attribute that accepts a distinguishedName. That includes distinguishedName, member, manager, and several others.
It looks like you just want to search by the account name though. You can search by the cn attribute, like this:
(&(objectClass=user)(cn=*Manager*))
That will find any user account with Manager in the name. Just be careful with that. If you use a wildcard at the beginning, it cannot use indexes to do the search. So in the query I just gave you, it would have to search through every user account to find matches. So the more criteria you can give it, the better.
Active Directory also has a special kind of search called Ambiguous Name Resolution, which is specifically designed for finding users without knowing the full name. It looks for your search term in several attributes, like first name and last name, and others. For example, you can make a search like this:
(anr=Michał Bednarz)
And it would find you, even if the displayName on your account is Bednarz, Michał.
You can also read here about the formatting of an LDAP query: Active Directory: LDAP Syntax Filters

Related

Mongodb Wildcard Searching without regex

I can see Wildcard Operator in https://docs.atlas.mongodb.com/reference/atlas-search/wildcard.
Can anyone share how exactly this is used.
Consider user model as
user = { 'email': 'jibrish#gmail.com', ...}
i tried
db.users.aggregate([{"$search":{"wildcard": { "path": "email", "query": "*"}}},{"$project":{"email": 1}}])
But this returns empty array!!
As you mentioned in the comment, that's the problem
You need to have index on parh field.
As in the documentation
Indexed field or fields to search. You can also specify a wildcard path to search. See path construction for more information.

Querying mongoDB using pymongo (completely new to mongo/pymongo)

If this question seems too trivial then please let me know in the comments, I will do further research on how to solve it.
I have a collection called products where I store details of a particular product from different retailers. The schema of a document looks like this -
{
"_id": "uuid of a product",
"created_at": "timestamp",
"offers": [{
"retailer_id": 123,
"product_url": "url - of -a - product.com",
"price": "1"
},
{
"retailer_id": 456,
"product_url": "url - of -a - product.com",
"price": "1"
}
]
}
_id of a product is system generated. Consider a product like 'iPhone X'. This will be a single document with URLs and prices from multiple retailers like Amazon, eBay, etc.
Now if a new URL comes into the system, I need to make a query if this URL already exists in our database. The obvious way to do this is to iterate every offer of every product document and see if the product_url field matches with the input URL. That would require loading up all the documents into the memory and iterate through the offers of every product one by one. Now my question arises -
Is there a simpler method to achieve this? Using pymongo?
Or my database schema needs to be changed since this basic check_if_product_url_exists() is too complex?
MongoDB provides searching within arrays using dot notation.
So your query would be:
db.collection.find({'offers.product_url': 'url - of -a - product.com'})
The same syntax works in MongoDB shell or pymongo.

Mongo function to find if superstring exists in array. Nodejs,

A document in my mongo 'companies' collection looks like this:
{
"companyName": "",
"companyIcon": "",
"domains": [
"companyDomainA.com",
"companyDomainB.dev"
],
"allowSubDomains": true
}
In my application the user enters his/her email address.
Using the Nodejs native mongo driver (https://mongodb.github.io/node-mongodb-native), I want to query (find) which company the user belongs to.
The problem is when the user enters the email as name#dept.companyDomainA.com.
I want to be able to query and find the company document of the user based on his email (subdomained 0 or more levels), ie. if the superstring of a string exists in an array in mongo.
(Caveat, I cannot store all the subdomains of the company as they are dynamic and can change at will)
Is there a regular expression way/db schema change way, to achieve this?
Thanks in advance!!
I would do it like this. First find the root domain from the email address. To do that I would split the email and fetch the domain first.
const email = "name#dept.companyDomainA.com";
const domain = email.split('#')[1]; // dept.companyDomainA.com
Now fetch the host (companyDomainA.com) from it. Follow this link.
So, I have found the root domain which is companyDomainA.com. Now run the find query.
db.collection('documents').find({"domains": "companyDomainA.com"});
I didn't test this code.

Unable to full text search in Solr

I have some data in solr. I want to search which name is Chinmay Sahu See below I have 3 results in output. But I got 3 instead of 1. Because Content name searched partially.
I want to full search those name having Chinmay Sahu only that contents will come.
Output:
"docs": [
{
"id": "741fde46a654879949473b2cdc577913",
"content_id": "1277",
"name": "Chinmay Sahu",
"_version_": 1596995745829879800
},
{
"id": "4e98d680efaab3afe051f3ddc00dc5f2",
"content_id": "1825",
"name": "Chinmay Panda",
"_version_": 1596995745829879800
}
{
"id": "741fde46a654879949473b2cdc577913",
"content_id": "1259",
"name": "Sasmita Sahu",
"_version_": 1596995745829879800
}
]
Query:
name:Chinmay Sahu
Expected :
"docs": [
{
"id": "741fde46a654879949473b2cdc577913",
"content_id": "1277",
"name": "Chinmay Sahu",
"_version_": 1596995745829879800
},
]
Please help
Try doing this
name:"Chinmay Sahu"
You need to do a phrase query to match the exact name.
I am guessing in your case the name field is using Standard tokenizer which will split tokens if whitespace is there. So while indexing in all the 3 docs there will be a token called "chinmay".
While you search using
name:Chinmay Sahu
Solr will search it like this since if there is no fieldName specified before a token solr automatically searches it in default_field.(however default field is removed from solr 7.3, So it depends on what version of solr are you using.
)
Name:chinmay AND default_field:sahu
So since all the three docs are having chinmay as a token in the index,the query will match all 3 docs.
Now i dont know what your default field is? can you post your solr schema? That way we can explain why you are seeing those 3 docs.
Since root545 already explained that field:foo bar will search for foo in field and bar in the default search field, I'll suggest that it seems like you don't want to concern yourself with the exact Lucene syntax for searching. The edismax query parser is well suited for separating the typed search string from what fields are being searched and whether you want all tokens to match.
The query in that case would be just Chinmay Sahu, while you'd set q.op=AND (all terms must match), defType=edismax (use the edismax query parser) and qf=name (search the name field):
q=Chinmay Sahu&q.op=AND&defType=edismax&qf=name
You can also tune the different phrase parameters to make sure that names with the tokens in the exact same sequence will be boosted higher than those that have them in the opposite sequence (i.e. Sahu Chinmay).
If this is a programmatic search where no user is actually typing in the suggestion, using a phrase search as suggested is the way to go (name:"Chinmay Sahu").
I would suggest using query like
name:(Chinmay Sahu)
And make sure default operator is AND either in settings or query string like q.op=AND
With that approach you can use user input much easier since you don't need to parse it too much.

U-SQL: How to skip files from analysis based on content

I have a lot of files each containing a set of json objects like this:
{ "Id": "1", "Timestamp":"2017-07-20T10:43:21.8841599+02:00", "Session": { "Origin": "WebClient" }}
{ "Id": "2", "Timestamp":"2017-07-20T10:43:21.8841599+02:00", "Session": { "Origin": "WebClient" }}
{ "Id": "3", "Timestamp":"2017-07-20T10:43:21.8841599+02:00", "Session": { "Origin": "WebClient" }}
etc.
Each file containts information about a specific type of session. In this case it are sessions from a Web App, but it could also be sessions of a Desktop App. In that case the value for Origin is "DesktopClient" instead of "WebClient"
For analysis purposes say I am only interested in DesktopClient sessions.
All files representing a session are stored in Azure Blob Storage like this:
container/2017/07/20/00399076-2b88-4dbc-ba56-c7afeeb9ef77.json
container/2017/07/20/00399076-2b88-4dbc-ba56-c7afeeb9ef78.json
container/2017/07/20/00399076-2b88-4dbc-ba56-c7afeeb9ef79.json
Is it possible to skip files of which the first line already makes it clear if it is not a DesktopClient session file, like in my example? I think it would save a lot of query resources if files that I know of do not contain the right session type can be skipped since they can be quit big.
At the moment my query read the data like this:
#RawExtract = EXTRACT [RawString] string
FROM #"wasb://plancare-events-blobs#centrallogging/2017/07/20/{*}.json"
USING Extractors.Text(delimiter:'\b', quoting : false);
#ParsedJSONLines = SELECT Microsoft.Analytics.Samples.Formats.Json.JsonFunctions.JsonTuple([RawString]) AS JSONLine
FROM #RawExtract;
...
Or should I create my own version of Extractors.Text and if so, how should I do that.
To answer some questions that popped up in the comments to the question first:
At this point we do not provide access to the Blob Store meta data. That means that you need to express any meta data either as part of the data in the file or as part of the file name (or path).
Depending on the cost of extraction and sizes of files, you can either extract all the rows and then filter out the rows where the beginning of the row is not fitting your criteria. That will extract all files and all rows from all files, but does not need a custom extractor.
Alternatively, write a custom extractor that checks for only the files that are appropriate (that may be useful if the first solution does not give you the performance and you can determine the conditions efficiently inside the extractors). Several example extractors can be found at http://usql.io in the example directory (including an example JSON extractor).

Resources