Spring数据MongoDB存储库方法按id列表删除

时间:2017-09-09 19:55:48

标签: spring mongodb spring-data-mongodb

我有以下文件:

@Document(collection = "decision_analysis")
public class DecisionAnalysis implements Serializable {

    @Id
    private String id;

...

}

我需要通过List<String> decisionAnalysisIds

删除多个MongoDB文档

如何正确编写Spring Data MongoDB存储库方法才能完成它?

以下不起作用:

void deleteByIds(List<String> decisionAnalysisIds); - 错误:找不到类型DecisionAnalysis的属性ID!你是说&#39; id&#39;?

void deleteById(List<String> decisionAnalysisIds); - 有效,但只删除一个文档

1 个答案:

答案 0 :(得分:5)

使用像这样的in子句:

[assembly: ExportRenderer(typeof(CustomMap), typeof(CustomMapRenderer))]
namespace neoFly_Montana.Droid
{
public class CustomMapRenderer : MapRenderer, IOnMapReadyCallback
{
    GoogleMap map;
    List<Position> routeCoordinates;
    List<CustomPin> customPins;
    Position userLocation;
    bool isDrawn;

    protected override void OnElementChanged(Xamarin.Forms.Platform.Android.ElementChangedEventArgs<Map> e)
    {
        base.OnElementChanged(e);

        if (e.OldElement != null)
        {
           //\ NativeMap.InfoWindowClick -= OnInfoWindowClick;
        }

        if (e.NewElement != null)
        {

            var formsMap = (CustomMap)e.NewElement;
            //pin
            customPins = formsMap.CustomPins;
            routeCoordinates = formsMap.RouteCoordinates;
            userLocation = formsMap.userLocation;

            ((MapView)Control).GetMapAsync(this);
        }
    }

    public void OnMapReady(GoogleMap googleMap)
    {
        map = googleMap;

        var polylineOptions = new PolylineOptions();
        polylineOptions.InvokeColor(0x66FF0000);

        foreach (var position in routeCoordinates)
        {
            polylineOptions.Add(new LatLng(position.Latitude, position.Longitude));
        }

        map.AnimateCamera(CameraUpdateFactory.NewLatLngZoom(new LatLng(userLocation.Latitude, userLocation.Longitude), 15.0f));
        map.AddPolyline(polylineOptions);
    }

    protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e)
    {
        base.OnElementPropertyChanged(sender, e);

        if (e.PropertyName.Equals("VisibleRegion") && !isDrawn)
        {
            NativeMap.Clear();
            //NativeMap.InfoWindowClick += OnInfoWindowClick;
            //NativeMap.SetInfoWindowAdapter(this);

            foreach (var pin in customPins)
            {
                var marker = new MarkerOptions();
                marker.SetPosition(new LatLng(pin.Pin.Position.Latitude, pin.Pin.Position.Longitude));
                marker.SetTitle(pin.Pin.Label);
                marker.SetSnippet(pin.Pin.Address);
                marker.SetIcon(BitmapDescriptorFactory.FromResource(Resource.Drawable.menusmiley));

                NativeMap.AddMarker(marker);
            }
            isDrawn = true;
        }
    }
}