查询mongodb是否有数据

2024-06-07 12:48:35 发布

您现在位置:Python中文网/ 问答频道 /正文

我的问题是

我想根据MongoDB上是否有数据采取行动

如果没有数据,我希望它用输入法输入数据,如果它以前输入过数据,我希望它继续

我写了一个这样的代码,但它不起作用:

okulvarmi = { "okul" }

okul = db.find(okulvarmi)

if okul == "null":
  print("No data is included. Please add.")

else:
  print("The data has already been added. You can continue the transaction.")

上面的代码不起作用

我该怎么做我说的系统


Tags: 数据no代码dbdataifismongodb
1条回答
网友
1楼 · 发布于 2024-06-07 12:48:35

“okul”变量的值为“null”,因此它是一个字符串

因此,最好尝试以下方法:

if len(okul) == 0:
    print("No data is included. Please add.")

相关问题 更多 >

    热门问题