AspNetCore.Docs
AspNetCore.Docs copied to clipboard
Web API with MongoDB: Missing AddControllers also path variable in macOS tab
I followed all the steps but when I got to "Test the web API" I just got nothing, a blank array for /Books and "not found" when I tried a specific book ID.
The DB connection info appears correct and I can see my Bookstore database and Books table in Compass and the sample data is exactly as suggested.
So how do you troubleshoot when there's no real error message that would help me figure out why the API returns a blank array instead of a list of my books?
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: 5240866d-d0a1-f0dd-7b2c-203e1d69bc4b
- Version Independent ID: 83a5cb3b-23bc-4f0c-cd1c-1d1ffeb1131a
- Content: Create a web API with ASP.NET Core and MongoDB
- Content Source: aspnetcore/tutorials/first-mongo-app.md
- Product: aspnet-core
- Technology: aspnetcore-tutorials
- GitHub Login: @wadepickett
- Microsoft Alias: wpickett
Hello! Thanks for contacting us. This sounds like a general question about using ASP.NET Core. While we try to look at and respond to all issues, for questions like this we recommend posting to a community support group like Stack Overflow with the asp.net-core
tag.
Potential bugs in the ASP.NET Core framework and product feedback can be reported at dotnet/aspnetcore issues (include full repro steps and cross-link to a repro project in GH when appropriate). For Visual Studio, use the Report a Problem gesture or Suggest a Feature gesture within VS, which open internal issues for the VS team. For Visual Studio Code, you can open an issue at microsoft/vscode issues.
I followed all the steps but when I got to "Test the web API" I just got nothing, a blank array for /Books and "not found" when I tried a specific book ID.
The DB connection info appears correct and I can see my Bookstore database and Books table in Compass and the sample data is exactly as suggested.
So how do you troubleshoot when there's no real error message that would help me figure out why the API returns a blank array instead of a list of my books?
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: 5240866d-d0a1-f0dd-7b2c-203e1d69bc4b
- Version Independent ID: 83a5cb3b-23bc-4f0c-cd1c-1d1ffeb1131a
- Content: Create a web API with ASP.NET Core and MongoDB
- Content Source: aspnetcore/tutorials/first-mongo-app.md
- Product: aspnet-core
- Technology: aspnetcore-tutorials
- GitHub Login: @wadepickett
- Microsoft Alias: wpickett
I know this is old, but I had the same issue. The tutorial seems to be missing a pretty crucial step between creating the controller and testing the app. I had to add the following lines to Program.cs
in order for it to work:
builder.Services.AddControllers();
app.MapControllers();
I followed all the steps but when I got to "Test the web API" I just got nothing, a blank array for /Books and "not found" when I tried a specific book ID. The DB connection info appears correct and I can see my Bookstore database and Books table in Compass and the sample data is exactly as suggested. So how do you troubleshoot when there's no real error message that would help me figure out why the API returns a blank array instead of a list of my books?
Document Details
⚠ Do not edit this section. It is required for learn.microsoft.com ➟ GitHub issue linking.
- ID: 5240866d-d0a1-f0dd-7b2c-203e1d69bc4b
- Version Independent ID: 83a5cb3b-23bc-4f0c-cd1c-1d1ffeb1131a
- Content: Create a web API with ASP.NET Core and MongoDB
- Content Source: aspnetcore/tutorials/first-mongo-app.md
- Product: aspnet-core
- Technology: aspnetcore-tutorials
- GitHub Login: @wadepickett
- Microsoft Alias: wpickett
I know this is old, but I had the same issue. The tutorial seems to be missing a pretty crucial step between creating the controller and testing the app. I had to add the following lines to
Program.cs
in order for it to work:builder.Services.AddControllers();
app.MapControllers();
Yes I noticed a few missing steps. If you think that's bad, try following the instructions for Mac OS. They straight-up forgot they were writing instructions for a different operating system in the middle and left in a bunch of instructions on modifying the PATH environment variable to run MongoDB commands. MacOS doesn't even have environment variables.
Thanks for letting us know this topic needs help and your experiences with it. We will get it fixed! Looks like a section must be accidentally outside the Visual Studio Windows tab area as a guess for starters and it is missing instruction. Will look at all three IDE versions of the tutorial fix and retest. Re-opening this issue.