protected WriteConcernResult ReadWriteConcernResult(MongoConnection connection, SendMessageWithWriteConcernResult sendMessageResult) { var writeConcernResultSerializer = BsonSerializer.LookupSerializer<WriteConcernResult>(); var replyMessage = connection.ReceiveMessage<WriteConcernResult>(ReaderSettings, writeConcernResultSerializer); if (replyMessage.NumberReturned == 0) { throw new MongoCommandException("Command 'getLastError' failed. No response returned", new BsonDocument("getLastError", 1)); } var writeConcernResult = replyMessage.Documents[0]; var mappedException = ExceptionMapper.Map(writeConcernResult); if (mappedException != null) { throw mappedException; } return writeConcernResult; }
protected SendMessageWithWriteConcernResult SendMessageWithWriteConcern( MongoConnection connection, Stream stream, int requestId, BsonBinaryReaderSettings readerSettings, BsonBinaryWriterSettings writerSettings, WriteConcern writeConcern) { var result = new SendMessageWithWriteConcernResult(); if (writeConcern.Enabled) { var maxDocumentSize = connection.ServerInstance.MaxDocumentSize; var fsync = (writeConcern.FSync == null) ? null : (BsonValue)writeConcern.FSync; var journal = (writeConcern.Journal == null) ? null : (BsonValue)writeConcern.Journal; var w = (writeConcern.W == null) ? null : writeConcern.W.ToGetLastErrorWValue(); var wTimeout = (writeConcern.WTimeout == null) ? null : (BsonValue)(int)writeConcern.WTimeout.Value.TotalMilliseconds; var getLastErrorCommand = new CommandDocument { { "getlasterror", 1 }, // use all lowercase for backward compatibility { "fsync", fsync, fsync != null }, { "j", journal, journal != null }, { "w", w, w != null }, { "wtimeout", wTimeout, wTimeout != null } }; // piggy back on network transmission for message var getLastErrorMessage = new MongoQueryMessage(writerSettings, DatabaseName + ".$cmd", QueryFlags.None, maxDocumentSize, 0, 1, getLastErrorCommand, null); getLastErrorMessage.WriteTo(stream); result.GetLastErrorCommand = getLastErrorCommand; result.GetLastErrorRequestId = getLastErrorMessage.RequestId; } connection.SendMessage(stream, requestId); return result; }
protected SendMessageWithWriteConcernResult SendMessageWithWriteConcern( MongoConnection connection, BsonBuffer buffer, int requestId, BsonBinaryReaderSettings readerSettings, BsonBinaryWriterSettings writerSettings, WriteConcern writeConcern) { var result = new SendMessageWithWriteConcernResult(); if (writeConcern.Enabled) { var maxDocumentSize = connection.ServerInstance.MaxDocumentSize; var fsync = (writeConcern.FSync == null) ? null : (BsonValue)writeConcern.FSync; var journal = (writeConcern.Journal == null) ? null : (BsonValue)writeConcern.Journal; var w = (writeConcern.W == null) ? null : writeConcern.W.ToGetLastErrorWValue(); var wTimeout = (writeConcern.WTimeout == null) ? null : (BsonValue)(int)writeConcern.WTimeout.Value.TotalMilliseconds; var getLastErrorCommand = new CommandDocument { { "getlasterror", 1 }, // use all lowercase for backward compatibility { "fsync", fsync, fsync != null }, { "j", journal, journal != null }, { "w", w, w != null }, { "wtimeout", wTimeout, wTimeout != null } }; // piggy back on network transmission for message var getLastErrorMessage = new MongoQueryMessage(writerSettings, DatabaseName + ".$cmd", QueryFlags.None, maxDocumentSize, 0, 1, getLastErrorCommand, null); getLastErrorMessage.WriteTo(buffer); result.GetLastErrorCommand = getLastErrorCommand; result.GetLastErrorRequestId = getLastErrorMessage.RequestId; } connection.SendMessage(buffer, requestId); return(result); }
protected WriteConcernResult ReadWriteConcernResult(MongoConnection connection, SendMessageWithWriteConcernResult sendMessageResult) { var writeConcernResultSerializer = BsonSerializer.LookupSerializer(typeof(WriteConcernResult)); var replyMessage = connection.ReceiveMessage <WriteConcernResult>(ReaderSettings, writeConcernResultSerializer, null); if (replyMessage.NumberReturned == 0) { throw new MongoCommandException("Command 'getLastError' failed. No response returned"); } var writeConcernResult = replyMessage.Documents[0]; writeConcernResult.Command = sendMessageResult.GetLastErrorCommand; writeConcernResult.ServerInstance = connection.ServerInstance; var mappedException = ExceptionMapper.Map(writeConcernResult); if (mappedException != null) { throw mappedException; } return(writeConcernResult); }