python - Exclude documents from query with duplicate fields value -


could me? how using mongoengine exclude queryset documents fields have same value?

suppose, have model:

class a(document):     = intfield()     b = intfield()     c = intfield() 

documents in db:

{'a':1, 'b':1, 'c':1 } {'a':1, 'b':1, 'c':2 } {'a':1, 'b':2, 'c':1 } 

query: a.objects() documents

how can query documents:

{'a':1, 'b':1, 'c':1 } {'a':1, 'b':2, 'c':1 } 

it should exclude documents, if queryset has document same values 'a' , 'b' together. such document should included in queryset once.

one way use aggregate, this:

pipe = {"$group": {"_id": {"a": "$a", "b": "$b", "c": "$c"}}} a.objects.aggregate(pipeline=pipe) 

another way query fields excluding _id, , calculate unique records out results.


Comments

Popular posts from this blog

jquery - How do you format the date used in the popover widget title of FullCalendar? -

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -