以下是我的用户Collection中的一些示例用户:
{_id: 1, profile: {firstName: Maggie, lastName: May}, role: {0: 'user', 1: 'acctOwner'}}
{_id: 2, profile: {firstName: John, lastName: Doe}, role: {0: 'user', 1: 'acctOwner'}}
{_id: 3, profile: {firstName: Alton, lastName: May, acctOwner: 1}, username: AltonMay321, role: {0: 'user', 1: 'subAcct'}}
{_id: 4, profile: {firstName: Mary, lastName: Doe, acctOwner: 2}, username: MaryDoe123, role: {0: 'user', 1: 'subAcct'}}
我想将这些帐户链接在一起,subAcct角色与相应的acctOwner相关联。将它们与来自另一个的信息连接起来,acctOwners存储各自subAcct的id和用户名,反之亦然我希望subAcct具有相应的acctOwner id。
所以我希望它最终看起来像这样:
{_id: 1, profile: {firstName: Maggie, lastName: May, subAcct: 3, subUsername: AltonMay321}, role: {0: 'user', 1: 'acctOwner'}}
{_id: 2, profile: {firstName: John, lastName: Doe, subAcct: 4, subUsername: MaryDoe123}, role: {0: 'user', 1: 'acctOwner'}}
{_id: 3, profile: {firstName: Alton, lastName: May, acctOwner: 1}, username: AltonMay321, role: {0: 'user', 1: 'subAcct'}}
{_id: 4, profile: {firstName: Mary, lastName: Doe, acctOwner: 2}, username: MaryDoe123, role: {0: 'user', 1: 'subAcct'}}
如何在脚本中实现这种类型的db操作?我目前使用Studio 3T的Intellishell进行按钮混合,但没有找到任何解决方案。
编辑:我希望搜索subAcct用户的'profile.acctOwner'值以匹配它们,但是我想在acctOwner中填充有关subAcct,'subUsername'和'subAcct'的信息。