使用replaceOne时,节点upsertedId为null

我使用replaceOne作为便捷方法更新文档或创build一个文档,如果它不存在。 问题是,在创build的情况下,我没有得到upsertedId 。 但是我需要创build的文档。

的package.json

 "mongodb": "^2.2.31" 

MongoDb服务器版本是3.4.6

this.collection.replaceOne(filter,item,{upsert:true,w:1})返回

 { modifiedCount: 0, matchedCount: 0, result: { "n": 1, "nModified": 0, "upserted": [ { "index": 0, "_id": null } ], "ok": 1 }, upsertedCount: 1 upsertedId: { "index": 0, "_id": null } } 

在数据库中,upsertedObject也是使用null _id创build的