Exemplo n.º 1
0
        protected override bool TrySetArgument(string name, BsonValue value)
        {
            switch (name)
            {
            case "filter":
                _filter = (BsonDocument)value;
                return(true);

            case "update":
                _update = value;
                return(true);

            case "upsert":
                _options.IsUpsert = value.ToBoolean();
                return(true);

            case "collation":
                _options.Collation = Collation.FromBsonDocument(value.AsBsonDocument);
                return(true);

            case "arrayFilters":
                var arrayFilters = new List <ArrayFilterDefinition>();
                foreach (BsonDocument arrayFilterDocument in value.AsBsonArray)
                {
                    var arrayFilter = new BsonDocumentArrayFilterDefinition <BsonDocument>(arrayFilterDocument);
                    arrayFilters.Add(arrayFilter);
                }
                _options.ArrayFilters = arrayFilters;
                return(true);
            }

            return(false);
        }
Exemplo n.º 2
0
        // public methods
        public override void Initialize(BsonDocument operation)
        {
            VerifyFields(operation, "name", "arguments");

            foreach (var argument in operation["arguments"].AsBsonDocument)
            {
                switch (argument.Name)
                {
                case "filter":
                    _filter = argument.Value.AsBsonDocument;
                    break;

                case "update":
                    _update = argument.Value.AsBsonDocument;
                    break;

                case "projection":
                    _options.Projection = argument.Value.AsBsonDocument;
                    break;

                case "sort":
                    _options.Sort = argument.Value.AsBsonDocument;
                    break;

                case "upsert":
                    _options.IsUpsert = argument.Value.ToBoolean();
                    break;

                case "returnDocument":
                    _options.ReturnDocument = (ReturnDocument)Enum.Parse(typeof(ReturnDocument), argument.Value.AsString);
                    break;

                case "collation":
                    _options.Collation = Collation.FromBsonDocument(argument.Value.AsBsonDocument);
                    break;

                case "arrayFilters":
                    var arrayFilters = new List <ArrayFilterDefinition>();
                    foreach (var arrayFilter in argument.Value.AsBsonArray)
                    {
                        var arrayFilterDefinition = new BsonDocumentArrayFilterDefinition <BsonDocument>(arrayFilter.AsBsonDocument);
                        arrayFilters.Add(arrayFilterDefinition);
                    }
                    _options.ArrayFilters = arrayFilters;
                    break;

                case "hint":
                    _options.Hint = argument.Value;
                    break;

                default:
                    throw new ArgumentException($"Unexpected argument: {argument.Name}.");
                }
            }
        }
Exemplo n.º 3
0
        private bool TryParseArrayFilters(BsonArray values, out List <ArrayFilterDefinition> arrayFilters)
        {
            arrayFilters = new List <ArrayFilterDefinition>();

            foreach (BsonDocument value in values)
            {
                var arrayFilter = new BsonDocumentArrayFilterDefinition <BsonValue>(value);
                arrayFilters.Add(arrayFilter);
            }

            return(true);
        }