我使用 c# 和 asp.net mvc (visual studio 2015)。当我尝试将 mongodb 连接到 c# 时,出现此错误:
MongoDB.Driver.MongoConfigurationException: The connection string 'mongodb:://localhost' is not valid.
错误来源是:
var client = new MongoClient(Settings.Default.bigdataconexionstrin);
这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using WebApplication5.Properties;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
namespace WebApplication5.Controllers
{
[Authorize]
public class HomeController : Controller
{
public IMongoDatabase db1;
public HomeController()
{
var client = new MongoClient(Settings.Default.bigdataconexionstrin);
MongoClientSettings settings = new MongoClientSettings();
settings.Server = new MongoServerAddress("localhost", 27017);
this.db1 = client.GetDatabase(Settings.Default.db);
}
public ActionResult Index()
{
return View();
}
}
}