因为ObjectId表示的是:“_id”的数据类型,后面的值为字符串,所以在使用根据_id查询的时候,写ObjectId会出现“Undefined variable 'ObjectId'”,运行就会报错“ObjectId' is not defined”。如图:

Python使用MongoDB根据id查询数据时出现“‘ObjectId‘ is not defined”

解决方法为引入bson模块。

Python使用MongoDB根据id查询数据时出现“‘ObjectId‘ is not defined”

最后即可根据所写要求查询对应数据。

相关文章:

  • 2021-12-13
  • 2022-12-23
  • 2021-07-26
  • 2022-01-11
  • 2022-12-23
  • 2022-03-02
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-07
  • 2021-10-16
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-06
相关资源
相似解决方案