db.restaurant_info.find({name:/pi/i})
Above mongodb query is returning the data from DB in the below format
{
"_id" : ObjectId("579cf26204aba69a41da82ad"),
"name" : "pizza hut",
"type" : "restaurant"
}
/* 2 */
{
"_id" : ObjectId("579cf26204aba69a41da82af"),
"name" : "Kai pi",
"type" : "restaurant"
}
/* 3 */
{
"_id" : ObjectId("579cf26404aba69a41da82c7"),
"name" : "pizza and pasta",
"type" : "restaurant"
}
/* 4 */
{
"_id" : ObjectId("579cf26504aba69a41da82d0"),
"name" : "Crispi chicken",
"type" : "restaurant"
}
/* 5 */
{
"_id" : ObjectId("579cf26504aba69a41da82d1"),
"name" : "Pita house",
"type" : "restaurant"
}
However, this query will be used for auto-population so if I use pi in the search text field, then all the recodrs start with pi should come before other records, e.g sequence I am expecting:
Pizza hut Pizza and pasta Pita house Kai pi Crispi chicken
if I modify the query with db.restaurant_info.find({name:/^pi/i}),
then it returns
Pizza hut Pizza and pasta Pita house
without
Kai pi Crispi Chicken
Please guide me which query should I use to get the sequence I am expecting.