Home:ALL Converter>Mongodb Docker image with Asp dotnet core API connection problem

Mongodb Docker image with Asp dotnet core API connection problem

Ask Time:2021-01-05T20:15:34         Author:Mai

Json Formatter

I am trying to develop a simple API using dotnet core API and MongoBD docker image based on the article found https://medium.com/@kristaps.strals/docker-mongodb-net-core-a-good-time-e21f1acb4b7b

I followed the article step by step, First I ran an instance of the mongo and mong-express images using the following docker file :

version: '3.8'

services:

  mongo:
      image: mongo
      container_name: mongo
      restart: always
      ports:
        - "27017:27017"
      volumes:
        - mongo-data:/data/db
  mongo-express:
      image: mongo-express
      container_name: mongo-express
      restart: always
      ports:
        - "8081:8081"
      depends_on:
        - mongo  
volumes:
  mongo-data:
    driver: local

The Error Message

https://localhost:5001/api/messages

An unhandled exception occurred while processing the request.
MongoCommandException: Command saslContinue failed: Authentication failed..
MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol<TCommandResult>.ProcessReply(ConnectionId connectionId, ReplyMessage<RawBsonDocument> reply)

MongoAuthenticationException: Unable to authenticate using sasl protocol mechanism SCRAM-SHA-256.
MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken)

Stack Query Cookies Headers Routing
MongoCommandException: Command saslContinue failed: Authentication failed..
MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol<TCommandResult>.ProcessReply(ConnectionId connectionId, ReplyMessage<RawBsonDocument> reply)
MongoDB.Driver.Core.WireProtocol.CommandUsingQueryMessageWireProtocol<TCommandResult>.ExecuteAsync(IConnection connection, CancellationToken cancellationToken)
MongoDB.Driver.Core.Authentication.SaslAuthenticator.AuthenticateAsync(IConnection connection, ConnectionDescription description, CancellationToken cancellationToken)

Show raw exception details
MongoAuthenticationException: Unable to authenticate using sasl protocol mechanism SCRAM-SHA-256.
MongoDB.Driver.Core.Connections.BinaryConnection.OpenHelperAsync(CancellationToken cancellationToken)
MongoDB.Driver.Core.Servers.Server.GetChannelAsync(CancellationToken cancellationToken)
MongoDB.Driver.Core.Operations.RetryableReadContext.InitializeAsync(CancellationToken cancellationToken)
MongoDB.Driver.Core.Operations.RetryableReadContext.CreateAsync(IReadBinding binding, bool retryRequested, CancellationToken cancellationToken)
MongoDB.Driver.Core.Operations.FindOperation<TDocument>.ExecuteAsync(IReadBinding binding, CancellationToken cancellationToken)
MongoDB.Driver.OperationExecutor.ExecuteReadOperationAsync<TResult>(IReadBinding binding, IReadOperation<TResult> operation, CancellationToken cancellationToken)
MongoDB.Driver.MongoCollectionImpl<TDocument>.ExecuteReadOperationAsync<TResult>(IClientSessionHandle session, IReadOperation<TResult> operation, ReadPreference readPreference, CancellationToken cancellationToken)
MongoDB.Driver.MongoCollectionImpl<TDocument>.UsingImplicitSessionAsync<TResult>(Func<IClientSessionHandle, Task<TResult>> funcAsync, CancellationToken cancellationToken)
MongoDB.Driver.IAsyncCursorSourceExtensions.ToListAsync<TDocument>(IAsyncCursorSource<TDocument> source, CancellationToken cancellationToken)
ErrorMessagesAPI.Models.MessageRepository.GetAllMessages() in MessageRepository.cs
+
            return await _context
ErrorMessagesAPI.Controllers.MessagesController.Get() in MessagesController.cs
+
            return new ObjectResult(await _repo.GetAllMessages());
lambda_method(Closure , object )
Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable+Awaiter.GetResult()
Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor+AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, object controller, object[] arguments)
System.Threading.Tasks.ValueTask<TResult>.get_Result()
System.Runtime.CompilerServices.ValueTaskAwaiter<TResult>.GetResult()
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask<IActionResult> actionResultValueTask)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextResourceFilter>g__Awaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(ref State next, ref Scope scope, ref object state, ref bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, object state, bool isCompleted)
Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)

In the Monog DB I've created a database named messagesdb with an empty collection named messages.

The collection syntax is like this:

{
   "text": "hello",
   "createdAt": "2015-11-08T13:15:15.363Z",
   "updatedAt": "2015-11-08T13:15:15.363Z",
   "id": "5638b363c5cd0825511690bd"
 }

Then Complete implementation can be found here ErrorMessageAPI GitHub Repo

Could anyone with an expert in Docker and .NET core help me, please

Author:Mai,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/65578735/mongodb-docker-image-with-asp-dotnet-core-api-connection-problem
yy