Wednesday, December 31, 2014

Build an Application to Connect to MongoDB on Azure

http://docs.mongodb.org/ecosystem/tutorial/build-an-application-to-connect-to-mongodb-on-azure/

below is the connection string:

mongodb://user:password$@xxxx1.cloudapp.net,xxxx2.cloudapp.net/dbname?replicaSet=rsName


using RegMSW.Core;
using MongoDB.Driver;
using MongoDB.Driver.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using RegMSW.Core.Models;

namespace RegMSW.Core
{
    public class MongoDbContext
    {
        private MongoDatabase db;
        private MongoServer server;
       
        public MongoDbContext(string database, bool safeMode = true)
        {
            string connStr = Properties.Settings.Default.connectString;
            var client = new MongoClient(connStr);
            server = client.GetServer();
            db = server.GetDatabase(database);
        }

No comments:

Post a Comment