I have a use case where storing an _id that is a composite of the following would be immensely useful:
- 96 bit int
- 96 bit int
- 96 bit int ObjectID
This works out as a 36 byte ASCII string. It will be byte reversed to become big endian.
I would like to query “Give me all documents where _id starts with {1} concatenate {2}.” This would return documents where _id matches components 1 & 2 above, with any 3.
Yes, this is a Cassandra approach. The rest of the query I have can only be done realistically in MongoDB.
How can I do this?
For reference, I am using C#.
With your IDs saved as a 36-byte ascii strings, you can use a regular expression match to find prefix substrings in the index.
The caveats for efficiently using an index with regular expressions in MongoDB are that:
The query would be similar to: