擅长:python、mysql、java
<p>我会用这种方式。我刚测试过这个,它对我仍然有效。以下内容直接引自<code>pymongo doc.</code>:</p>
<p><code>save(to_save[, manipulate=True[, safe=False[, **kwargs]]])</code></p>
<blockquote>
<p>Save a document in this collection.</p>
<p>If to_save already has an "_id" then
an update() (upsert) operation is performed and
any existing document with that "_id" is
overwritten. Otherwise an insert() operation is performed. In this
case if manipulate is True an "_id" will be added to to_save and this
method returns the "_id" of the saved document. If manipulate is False
the "_id" will be added by the server but this method will return
None.</p>
</blockquote>