为什么在一个更新中有两个$ push在mongodb中不起作用

时间:2016-09-17 19:48:34

标签: mongodb mongoose mongoose-schema

当我分别更新两个数组时,它工作正常。但是当我一起更新时,只有第二个阵列正在更新

[1 of 1] Compiling Main             ( /run/user/1000/stack8847/wxc-0.92.2.0/Setup.hs, /run/user/1000/stack8847/wxc-0.92.2.0/.stack-work/dist/x86_64-linux-nix/Cabal-1.22.5.0/setup/Main.o )
Linking /run/user/1000/stack8847/wxc-0.92.2.0/.stack-work/dist/x86_64-linux-nix/Cabal-1.22.5.0/setup/setup ...
Error: wx-config not found, please install wx-config before installing wxc

当notificationDr.update()单独用于notifications_Array_Object和groups_Array_Object时,它的工作正常。

1 个答案:

答案 0 :(得分:0)

您必须更改查询

发件人:

var update = {
    $push : {
      notifications_Array_Object : newNotification
    },
    $push : {
      groups_Array_Object : ObjectID(groupId)
    },
    $inc : {unreadNotifications_Integer : 1}
};

收件人:

var update = {
    $push : {
      notifications_Array_Object : newNotification, groups_Array_Object : ObjectID(groupId)
    }
    $inc : {unreadNotifications_Integer : 1}
};