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
Post a Comment