擅长:python、mysql、java
<p>只需添加到@ssytvane answer,并回答@Guarav:如果不存在“upsert=True”,则可以添加:</p>
<pre><code>def update_tags(ref, new_tag):
coll.update({'ref': ref}, {'$push': {'tags': new_tag}}, upsert = True)
</code></pre>
<p>或者</p>
<pre><code>def update_tags(ref, new_tag):
coll.update_one({'ref': ref}, {'$push': {'tags': new_tag}}, upsert = True)
</code></pre>