Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MongoDB,如何给予';未定义';在java驱动程序中?(null不起作用)_Java_Mongodb_Aggregation Framework - Fatal编程技术网

MongoDB,如何给予';未定义';在java驱动程序中?(null不起作用)

MongoDB,如何给予';未定义';在java驱动程序中?(null不起作用),java,mongodb,aggregation-framework,Java,Mongodb,Aggregation Framework,考虑以下示例聚合查询以查找字段是否存在: db.coll.aggregate({"$project":{"exists":{ "$cond" : [ {"$eq": ["$fieldName", undefined] } , "true" , "false" ]}}}) 该骨料在mongo shell中的作用与预期一致。但是在mongo shell中使用null代替undefined不起作用(为什么?),如下所示: db.coll.aggregate({"$project":{"exists

考虑以下示例聚合查询以查找字段是否存在:

db.coll.aggregate({"$project":{"exists":{ "$cond" : [ {"$eq": ["$fieldName", undefined] } , "true" ,  "false" ]}}})
该骨料在mongo shell中的作用与预期一致。但是在mongo shell中使用null代替undefined不起作用(为什么?),如下所示:

db.coll.aggregate({"$project":{"exists":{ "$cond" : [ {"$eq": ["$fieldName", null] } , "true" ,  "false" ]}}})
我想通过java驱动程序使用这个操作。 但我不知道如何将其转换为java驱动程序,因为它没有未定义的
。使用
null
代替未定义在java中也不起作用


为什么要这样设计?

您没有使用
$exists
操作符有什么原因吗?您可能还想查看:您计划对结果字段做什么?可能还有其他方法可以到达那里。我想根据此字段的值设置另一个字段。例如,如果此字段有“A”,则将“type”字段设置为type1,否则如果“B”,则将其设置为“type2”,否则如果字段不存在,则将其设置为“type3”。