我有以下文件:
{
_id: objectId("5aa7abb3c7dc133b0007e6e"),
name: "first course",
targets: Array
0: Object
id: "11111_rrrr",
value: "test"
1: Object
id: "22222_rrrr",
value: "hi"
}
所以,我想改变数组[i]的值。 我的解决方案是:
$update = array(
'targets.$[].value' => "New Value"
);
$result = Course::where("_id", $course_id)->update($update);
它改变了数组的所有值,我怎样才能解决我的问题?
答案 0 :(得分:0)
试试这个
df %>%
filter(row_number() <= sum(vec)) %>% #based on the comments from OP
mutate(Subset = rep(vec, vec)) %>%
group_by(grp = rep(seq_along(vec), vec), Blocks) %>%
summarise(Subset = first(Subset), n = n())%>%
ungroup %>%
spread(Blocks, n, fill = 0) %>%
select(-grp)
# A tibble: 3 x 5
# Subset `2D` `2E` `4F` `5E`
#* <dbl> <dbl> <dbl> <dbl> <dbl>
#1 2.00 1.00 1.00 0 0
#2 3.00 1.00 0 1.00 1.00
#3 2.00 2.00 0 0 0