擅长:python、mysql、java
<p>您误用了集合的insert方法。在此处查看:<a href="http://api.mongodb.org/python/current/api/pymongo/collection.html#pymongo.collection.Collection.insert" rel="nofollow">http://api.mongodb.org/python/current/api/pymongo/collection.html#pymongo.collection.Collection.insert</a></p>
<p>您需要插入的是一个文档。它应该是一个带有键和值的dict。简单地尝试插入字符串是不合适的。dumps返回json格式的字符串。如果您只是为了获取dict而转储它,则不需要json步骤。</p>
<p>准确插入文档的外观:</p>
<p>postings.insert({“key”:“value”})</p>
<p>或者直接将类实例转换为要存储为文档的dict,然后将其插入。它与json.dumps.loads()一起工作,因为这最终会给您一个指令</p>