mongoDB prefix wildcard: fulltext-search ($text) find part with search-string
Solution 1:
It's not possible to do it with $text
operator.
Text indexes are created with the terms included in the string value or in an array of strings and the search is based in those indices.
You can only group terms on a phrase but not take part of them.
Read $text
operator reference and text indexes description.
Solution 2:
I don't have enough reputation to comment jasenkoh solution, but this is clearly the best way to deal with this situation.
In OP situation, I would:
db.mycoll.createIndex( { foo: "text" } )
db.mycoll.createIndex( { foo: 1 } )
db.mycoll.find({$or: [{$text: {$search: 'uper'}}, {foo: {$regex: 'uper'}}]})
For better performances (but slightly different results), replace the last line with:
db.mycoll.find({$or: [{$text: {$search: 'uper'}}, {foo: {$regex: '^uper'}}]})