0

I have a model for mongoalchemy:

class ImportProductReport(mongo.Document):
    target = mongo.IntField(default=0)
    processed = mongo.IntField(default=0)
    is_in_process_remove_offers = mongo.BoolField(default=False)
    is_old_offers_removed = mongo.BoolField(default=False)
    ...

I need get records, where

  • ImportProductReport.is_in_process_remove_offers == False,

  • ImportProductReport.is_old_offers_removed == False,

  • ImportProductReport.target == ImportProductReport.processed.

Without last equal, all work good:

res = ImportProductReport.query\
    .filter(
        ImportProductReport.is_old_offers_removed == False,
        ImportProductReport.is_in_process_remove_offers == False
    )\
    .all()

But if I try to write something like this:

res = ImportProductReport.query\
    .filter(
        ImportProductReport.is_old_offers_removed == False,
        ImportProductReport.is_in_process_remove_offers == False,
        ImportProductReport.target == ImportProductReport.processed
    )\
    .all()

I have an error:

AttributeError: 'bool' object has no attribute 'obj'

Tell me, please, how to add this last condition in my query? :)

Vasiliy
  • 1
  • 1

1 Answers1

0

If it someone help, I found the answer to my question. Mongoalchemy allows queries with a syntax, similar to the syntax of the original MongoDB. Therefore, query, that I need, can be written as follows:

res = ImportProductReport.query\
    .filter({
        'is_old_offers_removed': False,
        'is_in_process_remove_offers': False,
        '$where': 'this.target == this.processed'
    })\
    .all()
Vasiliy
  • 1
  • 1