It will render the HTML for one document and is extracted in a partial view to avoid repeating the code. Create a View, _Document.cshtml inside of it. The other actions are simple, they are only a facade for the corresponding methods in DocumentService.Ĭreate a new folder ExploreDb inside the top level folder Views. Index will fetch the databases and collections, and if the user has selected a collection in a database, it will get a row from that collection and also the document count.
#RAZORSQL MONGODB DRIVER#
Select C#/.NET for Driver and 2.5 or later for Version.Ĭopy the connection string and save it for later.
Next, click Choose a connection method, and then select Connect your application. Of course, that’s an easy password to guess, so not something you’d want to use in a production environment, but for this demo it will be fine.
#RAZORSQL MONGODB CODE#
The code later in this post assumes the username is admin and the password abcd1234. If you want to access the database from another IP address, you must whitelist that too.Įnter a username and password, and click Create MongoDB User. It will whitelist your IP address, thus allowing access to your MongoDB database. Click Create Cluster when you are ready.Īfter the cluster is ready, click CONNECT, and you will see the screen below:Ĭlick Add Your Current IP Address, and then Add IP Address.
In the next screen you don’t have to change anything but you may choose between cloud hosting by Amazon (AWS), Google, and Microsoft (Azure) - and the region in the world where it will be hosted. Check I agree to the terms of service and privacy policy and click Get started free.Ĭlick Create a cluster in the panel Starter Clusters, the one that is “Starting at FREE”. Enter your email address, first name, last name, and a password you want to use for this service. Go to the MongoDB Atlas website, and click Start Free. Create a MongoDB Database for Your C# Application You are going to use MongoDB Atlas, which is a cloud database service with a free tier. In this post, you will build an ASP.NET Core MVC application that reads data from and writes data to a MongoDB database in the cloud. You can easily distribute a single database on multiple servers to increase performance. You can alter it as you wish at any time!Īnother major advantage of MongoDB, and most document databases, is that they scale well. This post takes a different approach, which also demonstrates how flexible MongoDB is.
#RAZORSQL MONGODB HOW TO#
Some MongoDB tutorials define model classes in C# and show how to read from and write to the database with them. You don’t need to define all fields upfront. Instead of storing data in tables and rows, you store documents in a structure very similar to objects in the memory of your application.