Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/11.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中使用两个条件进行更新_Mongodb - Fatal编程技术网

如何在mongodb中使用两个条件进行更新

如何在mongodb中使用两个条件进行更新,mongodb,Mongodb,我正在练习mongodb db.inventory.insertMany( [ { item: "canvas", qty: 100, size: { h: 28, w: 35.5, uom: "cm" }, status: "A" }, { item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" }, { item: "mat", qty: 85, size: { h: 27.9, w:

我正在练习mongodb

db.inventory.insertMany( [
   { item: "canvas", qty: 100, size: { h: 28, w: 35.5, uom: "cm" }, status: "A" },
   { item: "journal", qty: 25, size: { h: 14, w: 21, uom: "cm" }, status: "A" },
   { item: "mat", qty: 85, size: { h: 27.9, w: 35.5, uom: "cm" }, status: "A" },
   { item: "mousepad", qty: 25, size: { h: 19, w: 22.85, uom: "cm" }, status: "P" },
   { item: "notebook", qty: 50, size: { h: 8.5, w: 11, uom: "in" }, status: "P" },
   { item: "paper", qty: 100, size: { h: 8.5, w: 11, uom: "in" }, status: "D" },
   { item: "planner", qty: 75, size: { h: 22.85, w: 30, uom: "cm" }, status: "D" },
   { item: "postcard", qty: 45, size: { h: 10, w: 15.25, uom: "cm" }, status: "A" },
   { item: "sketchbook", qty: 80, size: { h: 14, w: 21, uom: "cm" }, status: "A" },
   { item: "sketch pad", qty: 95, size: { h: 22.85, w: 30.5, uom: "cm" }, status: "A" }
] );
我倾向于将“cm”和“in”分开,并对它们进行更新,但这不起作用

db.inventory.updateMany(
    { $or [ { "size.h": { $gt:8.75 }, "size.uom": "in" }, 
            {"size.h": { $gt:22.225 }, "size.uom": "cm"} ] },
    {
     $set: {status: "B"},
     $currentDate: {lastModified: true}
    }
)

2019-04-12T22:16:00.575-0700 E QUERY    [js] SyntaxError: missing : after property id @(shell):2:6

您这样做的方式是正确的,但是您有一个语法错误,即在
$或
之后缺少冒号:

db.inventory.updateMany(
    { $or: [ { "size.h": { $gt:8.75 }, "size.uom": "in" }, 
            {"size.h": { $gt:22.225 }, "size.uom": "cm"} ] },
    {
    $set: {status: "B"},
    $currentDate: {lastModified: true}
    }
)

您这样做的方式是正确的,但是您有一个语法错误,即在
$或
之后缺少冒号:

db.inventory.updateMany(
    { $or: [ { "size.h": { $gt:8.75 }, "size.uom": "in" }, 
            {"size.h": { $gt:22.225 }, "size.uom": "cm"} ] },
    {
    $set: {status: "B"},
    $currentDate: {lastModified: true}
    }
)

非常感谢。我没注意到我错过了“:”谢谢你!!我没注意到我漏掉了“:”