Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/arrays/12.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
Arrays MongoDB从数组中删除对象删除整个数组_Arrays_Mongodb_Object - Fatal编程技术网

Arrays MongoDB从数组中删除对象删除整个数组

Arrays MongoDB从数组中删除对象删除整个数组,arrays,mongodb,object,Arrays,Mongodb,Object,我有这样一份文件: { "_id" : 0, "name" : "aimee Zank", "scores" : [ { "type" : "exam", "score" : 1.463179736705023 }, {

我有这样一份文件:

{
        "_id" : 0,
        "name" : "aimee Zank",
        "scores" : [
                {
                        "type" : "exam",
                        "score" : 1.463179736705023
                },
                {
                        "type" : "quiz",
                        "score" : 11.78273309957772
                },
                {
                        "type" : "homework",
                        "score" : 6.676176060654615
                },
                {
                        "type" : "homework",
                        "score" : 35.8740349954354
                }
        ]
}
在该文档中,我想删除作业类型得分最低的分数。首先,我尝试在mongo shell上执行此操作,因此我手动输入值

 db.students.update({ _id:0}, {$unset: {"scores.score":6.676176060654615} })
该查询没有任何作用,因此我尝试在Google上搜索,在这里发现了一个关于从数组中删除对象的问题,我尝试了另一个查询:

db.students.update({ _id:0 }, { $unset: 
                                   { "scores": { 
                                        "homework": 6.676176060654615 } } }, false, true);
第二个查询成功了,但并不像我预期的那样,因为结果是错误的

{ "_id" : 0, "name" : "aimee Zank" }
要检查作业类型的最低值是否存在,我通过此查询找到:

db.students.find({"scores.score":6.676176060654615}).pretty();

如果只想删除/拉取
score=6.676176060654615
,只需使用以下查询:

db.collection.update({"_id":0},{"$pull":{"scores":{score: 6.676176060654615}}})

如果要查找最小值并将其从集合中删除。你需要做这是两个步骤。有关更多详细信息

这应该可以拉取
分数=6.676176060654615
。您可以使用find query检查
score=6.676176060654615
是否存在吗?我编辑了我的问题,并添加了用于检查是否存在的查找结果。使用$min我可以得到类型作业的最低分数吗?我再次尝试了你提供的查询,因为它类似于你发布的链接中的查询。