2

How can I create mongodb query, which returns all documents that matches query but can contain one letter diff

For example if I have these documents

{ username: "john", age: 15 },
{ username: "jack", age: 15 },
{ username: "gor", age: 15 },
{ username: "test", age: 15 },

And want to make query like this

db.user.find({
    username: "johm"
})

It should return first document.

Thank you.

Gor
  • 2,808
  • 6
  • 25
  • 46
  • Should the query return document where `username: 'ajohmm'`? – styvane Apr 13 '16 at 14:47
  • You are looking for something like the Levenshtein distance to rank the results. Check this probably related question http://stackoverflow.com/questions/12005490/mongodb-sort-results-by-search-term-similarity – joao Apr 13 '16 at 14:47

0 Answers0