The following code demonstrates an issue with the 'g' option
// This finds only THREE of the records
results = coll.find({Material: {'$regex':['nhtco.*', 'gi']}});
// This one ALSO finds only THREE (even with .* on front and back)
results = coll.find({Material: {'$regex':['.*nhtco.*', 'gi']}});
// This one correctly finds all SIX (removed 'g')
results = coll.find({Material: {'$regex':['.*nhtco.*', 'i']}});
// This one also finds all SIX
results = coll.find({Material: { '$regex':/nhtco.*/i }});
// This one finds only THREE (added the 'g')
results = coll.find({Material: { '$regex':/nhtco.*/gi }});
The last two results might be due to the way /regex/ does not serialize. But that does not excuse the first few results.
In my case removing 'g' works, as I don't need multiple matching. But for someone who does, take heed!
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Given this dataset:
The following code demonstrates an issue with the 'g' option
The last two results might be due to the way /regex/ does not serialize. But that does not excuse the first few results. In my case removing 'g' works, as I don't need multiple matching. But for someone who does, take heed!