public WriteConcernResult Execute(MongoConnection connection)
 {
     using (var buffer = new BsonBuffer(new MultiChunkBuffer(BsonChunkPool.Default), true))
     {
         var readerSettings = GetNodeAdjustedReaderSettings(connection.ServerInstance);
         var writerSettings = GetNodeAdjustedWriterSettings(connection.ServerInstance);
         var message        = new MongoDeleteMessage(writerSettings, CollectionFullName, _flags, _query);
         message.WriteToBuffer(buffer);
         return(SendMessageWithWriteConcern(connection, buffer, message.RequestId, readerSettings, writerSettings, WriteConcern));
     }
 }
Exemple #2
0
        // public methods
        public WriteConcernResult Execute(MongoConnection connection)
        {
            var serverInstance = connection.ServerInstance;

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

            var requests = _args.Requests.ToArray();

            if (requests.Length != 1)
            {
                throw new NotSupportedException("Delete Opcode only supports a single delete request.");
            }
            var deleteRequest = (DeleteRequest)requests[0];

            RemoveFlags flags;

            switch (deleteRequest.Limit)
            {
            case 0: flags = RemoveFlags.None; break;

            case 1: flags = RemoveFlags.Single; break;

            default: throw new NotSupportedException("Delete Opcode only supports limit values of 0 and 1.");
            }

            SendMessageWithWriteConcernResult sendMessageResult;

            using (var stream = new MemoryStream())
            {
                var maxDocumentSize = connection.ServerInstance.MaxDocumentSize;

                var message = new MongoDeleteMessage(WriterSettings, CollectionFullName, flags, maxDocumentSize, deleteRequest.Query);
                message.WriteTo(stream);

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

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