This is literally my first foray into Mongo. I have exported my Active Directory into a Mongo collection. It’s structure, as best I can describe it as a complete novice, is a row, with an object containing properties which contain an array of one string. (See attached image for clarification of my limited vocab).
My question is, I want to filter to a specific "givenname". What do I put in filter to do that? I tried {givenname: "Test"}, but it matches nothing. I suspect because I have to drill all the way down through the multiple layers. Probably something like:
{Properties: { givenname: 0: {"Test"}}}
I really do not know the json syntax (’cause that’s what it looks like) to go from row, to property {} object, to column [] array, to array element 0, to value "Test".
EDIT: Here is an example of the JSON I imported to create this data. It’s just a straight dump of an LDAP query, with PII edited out.
[
{
"Path": "LDAP://CN=My Name,OU=Admins,OU=Service Accounts,OU=asdf Company,DC=asdf,DC=local",
"Properties": {
"objectclass": [
"top",
"person",
"organizationalPerson",
"user"
],
"countrycode": [
0
],
"primarygroupid": [
513
],
"givenname": [
"MyName"
],
"codepage": [
0
],
"memberof": [
"CN=sp-Net-FDA-RW,OU=Sharepoint,OU=Permission Groups"
],
"samaccounttype": [
805306368
],
"description": [
"IS - MyName Acct."
],
"msds-supportedencryptiontypes": [
0
],
}
},
{
// more accounts...
}
]
As you can see it’s an array of objects, and each object’s properties is an array of one or more elements. But almost always an array of a single element. GivenName, for example.
2
Answers
Try:
As mentioned in the comments, if your goal is to match a document where any of entries in the
givenname
array have the requested string, then the syntax is simply:You can see how this works in this playground example.
This combines two concepts from MongoDB’s querying syntax:
Links to further reading on both topics are provided above. The two associated takeaways are, respectively:
The latter point is what helps address your latest comment:
You can see in the playground example that all three of these documents match the syntax above:
If you specifically wanted something different you could express a more verbose query to prevent the unwanted documents from being returned. But generally this portion of the language attempts to yield the results that are most likely what you are looking for in a less verbose manner.