-1
[{
    "title": "abc",
    "limit": 1
},
{
    "title": "airline filter",
    "limit": 1
},
{
    "title": "adnjn dnjnd",
    "limit": 1
},
{
    "title": "baudur",
    "limit": 1
},
{
    "title": "admin Panel",
    "limit": 1
}]

In the above code i need to search based on character means if we pass "a" then it will search title have "abc","airline filter" etc.. Can anyone help me

sidgate
  • 14,650
  • 11
  • 68
  • 119
Schüler
  • 1
  • 2
  • Let us know what you have tried – sidgate Feb 24 '17 at 08:04
  • I tried like this collection.createIndex( { title: "text" },function(err,result) { if(err) { callback('unable'); } else { collection.find({ $text: { $search: title, $language: "en" } }).toArray().then(function(entries) { callback(null, entries); }).catch(function(err) { callback(new Error(err)); }); } } ) – Schüler Feb 24 '17 at 08:10
  • Are you looking for documents where title begins with 'a' or title contains 'a'? – zendu Feb 24 '17 at 15:34

2 Answers2

0

Create a wildcard text index as mentioned here: https://docs.mongodb.com/v3.2/core/index-text/#wildcard-text-indexes and then use $text operator to search: https://docs.mongodb.com/v3.2/reference/operator/query/text/#op._S_text

zendu
  • 1,108
  • 1
  • 14
  • 36
  • I think misunderstood my question.. I dont want to search in different field.I need to search in one field but it wil filter title who have "a" character like this – Schüler Feb 24 '17 at 08:07
0

If you are looking for wild card searches in a collection, then this might help.

mongodb wildcard search with 'like'

If you are looking for any collection with a pattern, this might help.

search for collections that match a pattern

Community
  • 1
  • 1
SNrS
  • 33
  • 1
  • 3