0

I am accessing mongodb through parsepy in my django application. I have a name field in my db collection. I'm trying to get those name fields which match my query string.

For example, if I have these values--> food, folk, form, fill, filled, dust

If I query fo I should get food, folk, form.

If I query fi I should get fill, filled

I found that CollectionName.Query.filter(name__startswith=query) could do that. But unfortunately that is giving me empty queryset.

I tried it with CollectionName.Query.filter(name=ExactNameInDB) like CollectionName.Query.filter(name='food') and it returned me the collection object with that name as the queryset.

I even tried name__contains as keyword argument but that didn't work. This one is bugging me since a long time. Please help me. If you think that this explanation isn't enough, I can elaborate the context more.

Rohit Babu
  • 380
  • 3
  • 14
  • Are you sure that `__startswith` obtained `'fo'`? Did you hardcode that value? – Willem Van Onsem Jun 19 '19 at 19:37
  • @Willem Van Onsem No, __startswith is returning empty queryset. I harcoded `collectionName.Query.filter(name="food")` and that worked fine. I am using [parsepy wrapper](https://github.com/milesrichardson/ParsePy). – Rohit Babu Jun 19 '19 at 19:41
  • @WillemVanOnsem I just tried hardcoding the name to confirm whether it is sucessfully hitting db(ParsePy) or not. – Rohit Babu Jun 19 '19 at 19:50

0 Answers0