How to use `$or` in mongodb
<p>I am new to MongoDB and I have met an issue when I use <code>$or</code> operator.</p>

<p>Here is my code:</p>

<pre><code>for element in table1.find():
        total += 1
        result = table2.find_one({'guanZhi' : element['guanZhi'], 
                                  'name'    : element['name'],
                                  'minZu'   : element['minZu'],
                                  'keJu'    : element['keJu']})

        if result and (element['qiFen'] == result['qiFen'] or 
                       element['qiFen'] == result['qiFenHuo']):
            pass
        else:
            failed += 1
</code></pre>

<p>About <code>(element['qiFen'] == result['qiFen'] or element['qiFen'] == result['qiFenHuo'])</code>, I want use <code>$or</code>, but I don't know how to write the code.</p>

<p>I changed it like this:</p>

<pre><code>for element in table1.find({'ji': ""}):
        if table2.find_one({'guanZhi' : element['guanZhi'],
                            'name'    : element['name'],
                            'minZu'   : element['minZu'],
                            'nian'    : element['nian'],
                            '$or'     : [{'qiFen' : element['qiFen']}, {'qiFenHuo': element['qiFen']}]}):
            match.write(formatElement(element))
        else:
            no_match.write(formatElement(element))
            failed += 1
</code></pre>

<p>but I am confused with it, does this code look alright?
i want:</p>

<pre><code>(guanZhi' : element['guanZhi']) and 
('name' : element['name'])      and 
('minZu'   : element['minZu'])  and 
('keJu': element['keJu'])       and 
({'qiFen' : element['qiFen']}   or  {'qiFenHuo': element['qiFen']})
</code></pre>