[SERVER-267] Wildcard support in index/query/projection Created: 27/Aug/09 Updated: 06/Dec/22 |
|
| Status: | Backlog |
| Project: | Core Server |
| Component/s: | Index Maintenance, Querying |
| Affects Version/s: | 0.9.9 |
| Fix Version/s: | None |
| Type: | Improvement | Priority: | Major - P3 |
| Reporter: | Mina Naguib | Assignee: | Backlog - Query Optimization |
| Resolution: | Unresolved | Votes: | 67 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||||||||||||||||||||||||||||||||||||||
| Assigned Teams: |
Query Optimization
|
||||||||||||||||||||||||||||||||||||||||||||
| Participants: | |||||||||||||||||||||||||||||||||||||||||||||
| Case: | (copied to CRM) | ||||||||||||||||||||||||||||||||||||||||||||
| Description |
|
db.foo.ensureIndex( { "a.*.b" : 1 } ) ) ) |
| Comments |
| Comment by Asya Kamsky [ 15/Aug/17 ] |
|
Our index format/representation relies on field names being the same - that is, we don't store the names of the fields in the index, just the values. That may be problematic for fields containing wildcards. |
| Comment by Billy Tetrud [ 11/Aug/17 ] |
|
@Asya Why wouldn't it be possible? Should be just as easy to implement as any other index, right? |
| Comment by Asya Kamsky [ 11/Aug/17 ] |
|
As of 3.4.4 there are aggregation expressions that will allow querying by groups of fields (though granted somewhat awkwardly). I'm not sure if it's possible to support wildcards for indexing though. |
| Comment by Billy Tetrud [ 25/Jul/17 ] |
|
Mongo shouldn't be treating maps as second-class citizens. Anything that can be done with an array should be doable with an object. |
| Comment by Lucas Brynte [ 20/Apr/17 ] |
|
I truly agree! |
| Comment by Micheal Reed [ 27/Jan/17 ] |
|
Would open up the door for some great schema designs. Please add to roadmap. |
| Comment by Glenn Maynard [ 06/Feb/14 ] |
|
I've needed to do this before, due to MongoDB's limitations with handling arrays. I think that rather than supporting these queries, it'd be better to fix the limitations of arrays. After all, even if Mongo supports wildcard key queries, there would still be other things you couldn't do with dictionary values, like aggregation. Instead of enhancing dictionaries to let them do things we can already do with arrays (creating a lot of duplication of functionality in the process), enhance arrays so we don't need to use dictionaries like this in the first place.
|
| Comment by Nick Del Regno [ 17/Jun/13 ] |
|
I would also like to have this feature. I developed a schema for my current project, but then had to rework based on the inability to query using wildcard subkeys. For example: { , , I'd like to be able to query using db.collection.find( {"ports.$.state" : "no shutdown"}, {_id:1, ports:1}). This would return all of the ports, in all switches, which are shutdown. In lieu of this functionality, I am reevaluating my schema to determine how I can achieve the same effect without having to issue discrete finds for {"ports.1/1/1.state" : "no shutdown"}and {"ports.1/1/2.state" : "no shutdown"}, etc, since each switch will have different card/port configurations. |
| Comment by Israel Alvarez [ 20/Mar/13 ] |
|
Would also like to have this feature. Or even better, something like $elemMatch query operator that works on keys instead of values. |
| Comment by Bradford Smith [ 20/Jan/11 ] |
|
As a beginner MongoDB user, I had no idea that there was no support for this. Consequently, I modeled my data as follows: { , , } The reason for this is because I have an admin screen to edit notes and the URL is something like /editNotes?id=4d221860edc6ae20218cc50c db.stores.find({'notes.4d221860edc6ae20218cc50c': {$exists: true}}) This allows me to get the store document containing that note. And since I treat notes as Map<ObjectId, Notes> notes, I can then just do notes.get("4d221860edc6ae20218cc50c"); to get the notes for 4d221860edc6ae20218cc50c. The problem is it's really hard to maintain this. For example, let's say I want to set all notes to hide = false. How would I do this? I also had a related question in |
| Comment by Mike Harris [ 18/Dec/09 ] |
|
This is not complete at all, still many things to work on, but I have the beginnings of a patch here http://github.com/mharris717/mongo/commit/b27d8577a7c0bec037e5b0939f20bbf0e1b14337 Passes the basic test cases |