Hello everyone,
I’m trying to write a MongoDB query that finds documents based on whether any element in a stored array of URLs is a base path (i.e., prefix) of a given input URL.
Each document in my collection contains an array of base URLs:
{
"configuration": {
"urls": [
"https://example.com",
"https://anotherdomain.com/path"
]
},
...
}
Currently this query implemented with strict matching, so it would be best to build on this example:
result = await this.myEntityModel
.findOne({
'configuration.urls': {
$in: [payload.url],
},
})
.populate('...');
Is there a way to express this kind of “reverse prefix match” (incoming value starts with any element of a stored array) directly in a MongoDB query?
Thanks in advance for your help!