Example #1
0
        public override WriteConcernResult Save(BsonDocument document, WriteConcern writeConcern, bool needResult)
        {
            // copy, make id, override
            document = CloneExternalDocument(document);
            var id = document.EnsureId();
            bool updatedExisting = _data.ContainsKey(id);
            _data[id] = document;

            return needResult ? new WriteConcernResult(NewResponse(1, updatedExisting, null, null)) : null;
        }
Example #2
0
        public override WriteConcernResult Save(BsonDocument document, WriteConcern writeConcern, bool needResult)
        {
            // copy, make id, override
            document = CloneExternalDocument(document);
            var  id = document.EnsureId();
            bool updatedExisting = _data.ContainsKey(id);

            _data[id] = document;

            return(needResult ? new WriteConcernResult(NewResponse(1, updatedExisting, null, null)) : null);
        }
Example #3
0
        protected override void InsertInternal(BsonDocument document)
        {
            // make id
            BsonValue id;

            if (!document.TryGetValue(MyValue.Id, out id))
            {
                id = document.EnsureId();
            }
            else if (id.BsonType == BsonType.Array)
            {
                throw new InvalidOperationException("Can't use an array for _id.");
            }

            // try to add
            try
            {
                _data.Add(id, document);
            }
            catch (ArgumentException)
            {
                ThrowIdExists(id);
            }
        }
Example #4
0
        protected override void InsertInternal(BsonDocument document)
        {
            // make id
            BsonValue id;
            if (!document.TryGetValue(MyValue.Id, out id))
                id = document.EnsureId();
            else if (id.BsonType == BsonType.Array)
                throw new InvalidOperationException("Can't use an array for _id.");

            // try to add
            try
            {
                _data.Add(id, document);
            }
            catch (ArgumentException)
            {
                ThrowIdExists(id);
            }
        }