コード例 #1
0
        // public methods
        public WriteConcernResult Execute(MongoConnection connection)
        {
            var serverInstance = connection.ServerInstance;
            if (serverInstance.Supports(FeatureId.WriteCommands) && _args.WriteConcern.Enabled)
            {
                var emulator = new UpdateOpcodeOperationEmulator(_args);
                return emulator.Execute(connection);
            }

            SendMessageWithWriteConcernResult sendMessageResult;
            using (var buffer = new BsonBuffer(new MultiChunkBuffer(BsonChunkPool.Default), true))
            {
                var requests = _args.Requests.ToList();
                if (requests.Count != 1)
                {
                    throw new NotSupportedException("Update opcode only supports a single update request.");
                }
                var updateRequest = (UpdateRequest)requests[0];

                var flags = UpdateFlags.None;
                if (updateRequest.IsMultiUpdate ?? false) { flags |= UpdateFlags.Multi; }
                if (updateRequest.IsUpsert ?? false) { flags |= UpdateFlags.Upsert; }

                var maxDocumentSize = connection.ServerInstance.MaxDocumentSize;
                var query = updateRequest.Query ?? new QueryDocument();

                var message = new MongoUpdateMessage(WriterSettings, CollectionFullName, _args.CheckElementNames, flags, maxDocumentSize, query, updateRequest.Update);
                message.WriteTo(buffer);

                sendMessageResult =  SendMessageWithWriteConcern(connection, buffer, message.RequestId, ReaderSettings, WriterSettings, WriteConcern);
            }

            return WriteConcern.Enabled ? ReadWriteConcernResult(connection, sendMessageResult) : null;
        }
コード例 #2
0
        // public methods
        public WriteConcernResult Execute(MongoConnection connection)
        {
            var serverInstance = connection.ServerInstance;

            if (serverInstance.Supports(FeatureId.WriteCommands) && _args.WriteConcern.Enabled)
            {
                var emulator = new UpdateOpcodeOperationEmulator(_args);
                return(emulator.Execute(connection));
            }

            SendMessageWithWriteConcernResult sendMessageResult;

            using (var stream = new MemoryStream())
            {
                var requests = _args.Requests.ToList();
                if (requests.Count != 1)
                {
                    throw new NotSupportedException("Update opcode only supports a single update request.");
                }
                var updateRequest = (UpdateRequest)requests[0];

                var flags = UpdateFlags.None;
                if (updateRequest.IsMultiUpdate ?? false)
                {
                    flags |= UpdateFlags.Multi;
                }
                if (updateRequest.IsUpsert ?? false)
                {
                    flags |= UpdateFlags.Upsert;
                }

                var maxDocumentSize = connection.ServerInstance.MaxDocumentSize;
                var query           = updateRequest.Query ?? new QueryDocument();

                var message = new MongoUpdateMessage(WriterSettings, CollectionFullName, _args.CheckElementNames, flags, maxDocumentSize, query, updateRequest.Update);
                message.WriteTo(stream);

                sendMessageResult = SendMessageWithWriteConcern(connection, stream, message.RequestId, ReaderSettings, WriterSettings, WriteConcern);
            }

            return(WriteConcern.Enabled ? ReadWriteConcernResult(connection, sendMessageResult) : null);
        }