如何删除mongo Db中的嵌套数组元素

时间:2017-05-24 13:50:49

标签: arrays node.js mongodb nested-attributes

“如何从mongo db的结构中删除嵌套数组'accounts'中的单个元素(图中也显示)。我可以使用$ pull方法吗?任何人都知道请分享你的想法”。< / p>

 "associatedAccounts" : [ 
        {
            "organizationId" : "5808ba773fe315441b9e0a9e",
            "_id" : ObjectId("5808bc0c3fe315441b9e0b1a"),
            "accounts" : [ 
                "5808baf33fe315441b9e0aa7", 
                "5808baf33fe315441b9e0aa8", 
                "5808baf33fe315441b9e0aa1"
            ]
        }, 
        {
            "organizationId" : "5808ba773fe315441b9e0a9f",
            "_id" : ObjectId("5808bc0c3fe315441b9e0b1b"),
            "accounts" : [ 
                "5808baf33fe315441b9e0aa3", 
                "5808baf33fe315441b9e0aa2", 
                "5808baf33fe315441b9e0aa5", 
                "5808baf33fe315441b9e0aa6"
            ]
        }
    ]

enter image description here

1 个答案:

答案 0 :(得分:0)

您可以在Button的基础上删除,因为Id在Mongodb中是唯一标识

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:ExLuminaControls">

<Style x:Key="FocusVisual">
    <Setter Property="Control.Template">
        <Setter.Value>
            <ControlTemplate>
                <Rectangle Margin="2"
                           SnapsToDevicePixels="true"
                           Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"
                           StrokeThickness="1"
                           StrokeDashArray="1 2"/>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>

<SolidColorBrush x:Key="Button.Static.Border" Color="#FF707070"/>

<Style TargetType="{x:Type local:XLButton}">
    <Setter Property="FocusVisualStyle" Value="{StaticResource FocusVisual}"/>
    <Setter Property="BorderBrush" Value="{StaticResource Button.Static.Border}"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="HorizontalContentAlignment" Value="Center"/>
    <Setter Property="VerticalContentAlignment" Value="{x:Null}"/>
    <Setter Property="Padding" Value="1"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type local:XLButton}">
                <Grid>
                    <Border x:Name="border"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Background="{TemplateBinding Background}"
                            SnapsToDevicePixels="true"/>
                    <Rectangle x:Name ="glow" Fill="White" Opacity="0"/>
                    <Rectangle x:Name="shade" Fill="Black" Opacity="0"/>
                    <ContentPresenter x:Name="contentPresenter"
                                      Focusable="False"
                                      HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                      Margin="{TemplateBinding Padding}"
                                      RecognizesAccessKey="True"
                                      SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                      VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    <Rectangle x:Name="dis" Fill="Gray" Opacity="0"/>
                    <Rectangle x:Name="foc" Margin="4" SnapsToDevicePixels="true"
                               Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"
                               StrokeThickness="1" Opacity="0"/>
                    <VisualStateManager.VisualStateGroups>
                        <VisualStateGroup Name="CommonStates">
                            <VisualState Name="Normal">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="glow"
                                                         Storyboard.TargetProperty="Opacity"
                                                         To="0" Duration="0:0:.1"/>
                                </Storyboard>
                            </VisualState>
                            <VisualState Name="MouseOver">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="glow"
                                                         Storyboard.TargetProperty="Opacity"
                                                         To=".25" Duration="0:0:.1"/>
                                </Storyboard>
                            </VisualState>
                            <VisualState Name="Pressed">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="shade"
                                                         Storyboard.TargetProperty="Opacity"
                                                         To=".25" Duration="0:0:0"/>
                                </Storyboard>
                            </VisualState>
                            <VisualState Name="Disabled">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="dis"
                                                         Storyboard.TargetProperty="Opacity"
                                                         To=".25" Duration="0:0:0"/>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                        <VisualStateGroup Name="FocusStates">
                            <VisualState Name="Focused">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="foc"
                                                         Storyboard.TargetProperty="Opacity"
                                                         To="1" Duration="0:0:.1"/>
                                </Storyboard>
                            </VisualState>
                            <VisualState Name="Unfocused">
                                <Storyboard>
                                    <DoubleAnimation Storyboard.TargetName="foc"
                                                         Storyboard.TargetProperty="Opacity"
                                                         To="0" Duration="0:0:.1"/>
                                </Storyboard>
                            </VisualState>
                        </VisualStateGroup>
                    </VisualStateManager.VisualStateGroups>
                </Grid>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
</ResourceDictionary>

accountsId将是来自associatedAccounts的唯一ID,即此数组中存在的每个对象的_id。

_id将删除id与查询匹配的特定对象。