MongoDB 中,插入数据时,如果一个 Collection 不存在会先创建 Collection 再插入数据。

但是如果是在一个事务里,就不允许创建新的 Collection事件发生。否则会报错:

(OperationNotSupportedInTransaction) Cannot create namespace testdb.xxx in multi-document transaction.

因此需要提前创建好 Collection:

db.createCollection("xxx")

相关文章:

  • 2021-06-13
  • 2021-10-24
  • 2022-12-23
  • 2021-11-12
  • 2021-09-11
  • 2021-06-19
猜你喜欢
  • 2022-02-23
  • 2021-07-21
  • 2021-10-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-27
相关资源
相似解决方案