How is the mongoengine filter field non-zero?

I want to filter data using a value category, but I do not know how to do this in mongoengine.

I'm trying to:

data = Data.objects.exclude(category="").order_by('-datetime')[:500]  

But there was an error:

exclude() got an unexpected keyword argument 'category'

I did not find the method in the document, how do you do this?

+4
source share
2 answers

I have a feeling that you are mixing two concepts: filtering documents and returning subsets of documents.

Return a subset of documents

exclude mongo . , , : . , , . exclude only , exclude blacklists, only - .

Queryset:

data = Data.objects({'category':{'$ne':''}}).order_by('-datetime')[:500]

:

data = Data.objects(category__ne='').order_by('-datetime')[:500]

. .

+2

.exclude() ; . , , - , category__ne=''

data = Data.objects(category__ne='').order_by('-datetime')[:500] 
+1
source

Source: https://habr.com/ru/post/1617190/


All Articles