【问题标题】:How to insert an item into an array that's in an array that's also in an array如何将项目插入到数组中的数组中,该数组也在数组中
【发布时间】:2018-05-21 05:19:10
【问题描述】:

我正在尝试将一个项目插入到多维数组中,但我不知道该怎么做。

    Meteor.users.update(
       { _id: Meteor.userId() }, { $push: {profile: { friends: "hey" } }}
    );

【问题讨论】:

  • 你能展示你的架构吗?
  • profile是对象数组还是数组数组?

标签: arrays mongodb meteor


【解决方案1】:
Meteor.users.update(
   { _id: Meteor.userId() }, { $push: {'profile.friends': 'hey'} }
 );

【讨论】:

  • 如果profile 是一个对象并且friends 是该对象的一个​​引用数组的键,这将起作用。如果profile 是一个数组,它将不起作用。
猜你喜欢
  • 2017-10-24
  • 1970-01-01
  • 1970-01-01
  • 2014-03-13
  • 2022-01-13
  • 2013-06-02
  • 1970-01-01
  • 2020-12-11
  • 1970-01-01
相关资源
最近更新 更多