3.4.2.7 判断某个字段是否存在

使用“$exists”可以判断某个字段是否存在,如果设置为true表示存在,false表示不存在。

范例:查询具有parents成员的数据

db.students.find({"parents" : {"$exists" : true}}).pretty()

MongoDB(课时12 字段判断)

MongoDB(课时12 字段判断)

范例:查询不具有course成员的数据

db.students.find({"course" : {"$exists" : false}}).pretty()

MongoDB(课时12 字段判断)

MongoDB(课时12 字段判断)

可以利用此类查询来进行一些不需要的数据的过滤。 

 

相关文章:

  • 2021-10-03
  • 2021-12-10
  • 2022-12-23
  • 2022-12-23
  • 2021-12-06
  • 2021-11-02
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-20
  • 2021-12-09
  • 2022-12-23
  • 2021-08-09
  • 2022-12-23
  • 2021-06-04
相关资源
相似解决方案