It could be helpful to provide a new operator, similar to $all for arrays, that matches an ordered subset of items:
db.test.insert(
{'actions': [2, 6, 3, 8, 5, 3]});
db.test.insert(
);
// This should find the first document, but not the second as only the first contains [6, 3, 8] in order
db.test.find({'actions': {'$contains': [6, 3, 8]}});
A couple of use cases:
- Phrase matching in full-text search (storing stemmed terms as strings in an array)
- Finding users on a website that have performed a certain sequence of actions
Also, allowing it to be optionally anchored to the start or end of an array would open up more possibilities:
- Storing paths to files as individual segments of the path (by splitting the path by '/'), then finding files under a certain directory
(or more generically, querying on items that have a list that is a path in a tree/hierarchy or a graph).
- related to
-
SERVER-974 $subset query operator
- Closed