MongoDB: insert documents with specific id instead of auto generated ObjectID

后端 未结 2 1663
没有蜡笔的小新
没有蜡笔的小新 2021-01-19 19:13

I need to insert documents on MongoDB (with specific id instead of auto generated ObjectID) using java..

  1. To insert one document or update if exist, I tried

2条回答
  •  礼貌的吻别
    2021-01-19 19:35

    Try this @ebt_dev:

    db.collection("collectionname").insertOne(data, { forceServerObjectId: false })
    

提交回复
热议问题