MongoDB节点:在对象内部数组中动态添加键值数组元素

时间:2019-04-05 05:11:13

标签: node.js mongodb aggregation-framework

您好,我正在尝试在使用水线orm的节点的api中实现以下逻辑。

var modulename ='app用户列表'//发布数据

^               # Make sure the match begins at the start of the string
(?:             # Start a non-capturing group that matches...
    -?          # an optional minus sign,
    \d+         # one or more digits
    (?:\.\d+)?  # an optional group that contains a dot and one or more digits.
    (?:         # Start of a non-capturing group that either matches...
       [+*/-]   # an operator
    |           # or
       $        # the end of the string.
    )           # End of inner non-capturing group
)+              # End of outer non-capturing group, required to match at least once.
(?<![+*/-])     # Make sure that the final character isn't an operator.
$               # Make sure that the match ends at the end of the string.

仪表板,产品管理键是模块名称,值是这两个操作均来自用户端的操作数组。

我想在mongodb中实现它,下面是我的条件:

  1. 如果记录根本不存在,请使用user_id查找使用记录,创建它。
  2. 如果用户存在,请查找模块名称,如果找到,请检查操作并更新/插入不存在的模块。
  3. 如果用户存在,但模块名不存在,请插入带操作的模块名。

我是mongo的新手,我已经看到有$ addToSet和$ set操作符可用。

0 个答案:

没有答案