我的结构如下所示:
"_id" : { "$oid" : "502ac2858386b3f419000002"} ,
"eventName" : "eventA" ,
"eventStreamName" : "eventA-0001" ,
"encoders" : [
{
"encoderName" : "enc-201" ,
"streams" : [
{ "language" : "eng" , "format" : "flash" , "priority" : "primary"} ,
{ "language" : "spa" , "format" : "flash" , "priority" : "primary"} ,
{ "language" : "fra" , "format" : "flash" , "priority" : "primary"}
]
} ,
{
"encoderName" : "enc-202" ,
"streams" : [
{ "language" : "eng" , "format" : "flash" , "priority" : "primary"} ,
{ "language" : "spa" , "format" : "flash" , "priority" : "primary"} // i'd like to add stream here
]
}
]
我想将一个项目推送到编码器名称 = 'enc-202' 和 eventName = 'eventA' 的流数组
这是我尝试过的
$this->liveEvents = $db->selectCollection("liveEvents");
$newStream = array("language" => "ger",
"format" => "flash",
"priority" => "primary");
$filter = array("eventName" => "eventA",
"encoders.encoderName" => "enc-202");
$update = array('$push'=>array('encoders.streams'=>$newStream));
$this->liveEvents->update($filter,$update);
但它不工作。我不确定是否可以将 2 个项目添加到我的 $filter 中,并且我的 $update 也可能关闭。
刚接触 mongodb。任何帮助都会很棒。谢谢!