本文整理汇总了C#中MongoDB.Driver.MongoCredentials类的典型用法代码示例。如果您正苦于以下问题:C# MongoCredentials类的具体用法?C# MongoCredentials怎么用?C# MongoCredentials使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MongoCredentials类属于MongoDB.Driver命名空间,在下文中一共展示了MongoCredentials类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MongoServerSettings
public MongoServerSettings(
ConnectionMode connectionMode,
TimeSpan connectTimeout,
MongoCredentials defaultCredentials,
TimeSpan maxConnectionIdleTime,
TimeSpan maxConnectionLifeTime,
int maxConnectionPoolSize,
int minConnectionPoolSize,
string replicaSetName,
SafeMode safeMode,
IEnumerable<MongoServerAddress> servers,
bool slaveOk,
TimeSpan socketTimeout,
int waitQueueSize,
TimeSpan waitQueueTimeout
)
{
this.connectionMode = connectionMode;
this.connectTimeout = connectTimeout;
this.defaultCredentials = defaultCredentials;
this.maxConnectionIdleTime = maxConnectionIdleTime;
this.maxConnectionLifeTime = maxConnectionLifeTime;
this.maxConnectionPoolSize = maxConnectionPoolSize;
this.minConnectionPoolSize = minConnectionPoolSize;
this.replicaSetName = replicaSetName;
this.safeMode = safeMode;
this.servers = servers;
this.slaveOk = slaveOk;
this.socketTimeout = socketTimeout;
this.waitQueueSize = waitQueueSize;
this.waitQueueTimeout = waitQueueTimeout;
}
示例2: MongoDatabaseSettings
public MongoDatabaseSettings(
string databaseName,
MongoCredentials credentials,
GuidRepresentation guidRepresentation,
ReadPreference readPreference,
WriteConcern writeConcern)
{
if (databaseName == null)
{
throw new ArgumentNullException("databaseName");
}
if (databaseName == "admin" && credentials != null && !credentials.Admin)
{
throw new ArgumentOutOfRangeException("credentials", "Credentials for the admin database must have the admin flag set to true.");
}
if (readPreference == null)
{
throw new ArgumentNullException("readPreference");
}
if (writeConcern == null)
{
throw new ArgumentNullException("writeConcern");
}
_databaseName.Value = databaseName;
_credentials.Value = credentials;
_guidRepresentation.Value = guidRepresentation;
_readPreference.Value = readPreference;
_writeConcern.Value = writeConcern;
}
示例3: Main
static void Main(string[] args)
{
var server = MongoServer.Create("mongodb://localhost");
MongoDatabase test = server.GetDatabase("test");
MongoCredentials credentials = new MongoCredentials("username", "password");
MongoDatabase salaries = server.GetDatabase("salaries", credentials);
MongoCollection docs = test.GetCollection("docs");
docs.EnsureIndex("title");
Console.WriteLine("adding some test documents");
for (int x = 0; x < 1000; x++) {
BsonDocument doc = new BsonDocument();
doc.Add("title", "title: " + x);
doc.Add("body", "body: " + x);
docs.Insert(doc);
}
Console.WriteLine("querying");
foreach (var doc in docs.FindAllAs<BsonDocument>()) {
Console.WriteLine("doc: {0}", doc["body"]);
}
}
示例4: TestEquals
public void TestEquals()
{
var a = new MongoCredentials("user1", "password");
var b = new MongoCredentials("user1", "password");
var c = new MongoCredentials("user2", "password");
var n = (MongoCredentials)null;
Assert.IsTrue(object.Equals(a, b));
Assert.IsFalse(object.Equals(a, c));
Assert.IsFalse(a.Equals(n));
Assert.IsFalse(a.Equals(null));
Assert.IsTrue(a == b);
Assert.IsFalse(a == c);
Assert.IsFalse(a == null);
Assert.IsFalse(null == a);
Assert.IsTrue(n == null);
Assert.IsTrue(null == n);
Assert.IsFalse(a != b);
Assert.IsTrue(a != c);
Assert.IsTrue(a != null);
Assert.IsTrue(null != a);
Assert.IsFalse(n != null);
Assert.IsFalse(null != n);
}
示例5: MongoServerSettings
// constructors
/// <summary>
/// Creates a new instance of MongoServerSettings. Usually you would use a connection string instead.
/// </summary>
public MongoServerSettings()
{
_connectionMode = ConnectionMode.Automatic;
_connectTimeout = MongoDefaults.ConnectTimeout;
_credentialsStore = new MongoCredentialsStore();
_defaultCredentials = null;
_guidRepresentation = MongoDefaults.GuidRepresentation;
_ipv6 = false;
_maxConnectionIdleTime = MongoDefaults.MaxConnectionIdleTime;
_maxConnectionLifeTime = MongoDefaults.MaxConnectionLifeTime;
_maxConnectionPoolSize = MongoDefaults.MaxConnectionPoolSize;
_minConnectionPoolSize = MongoDefaults.MinConnectionPoolSize;
_readPreference = ReadPreference.Primary;
_replicaSetName = null;
_secondaryAcceptableLatency = MongoDefaults.SecondaryAcceptableLatency;
_servers = new List<MongoServerAddress> { new MongoServerAddress("localhost") };
_socketTimeout = MongoDefaults.SocketTimeout;
_useSsl = false;
_verifySslCertificate = true;
_waitQueueSize = MongoDefaults.ComputedWaitQueueSize;
_waitQueueTimeout = MongoDefaults.WaitQueueTimeout;
#pragma warning disable 612, 618
_writeConcern = MongoDefaults.SafeMode.WriteConcern;
#pragma warning restore
}
示例6: MongoDatabaseSettings
/// <summary>
/// Creates a new instance of MongoDatabaseSettings.
/// </summary>
/// <param name="databaseName">The name of the database.</param>
/// <param name="credentials">The credentials to access the database.</param>
/// <param name="guidRepresentation">The representation for Guids.</param>
/// <param name="readPreference">The read preference.</param>
/// <param name="safeMode">The safe mode to use.</param>
public MongoDatabaseSettings(
string databaseName,
MongoCredentials credentials,
GuidRepresentation guidRepresentation,
ReadPreference readPreference,
SafeMode safeMode)
{
if (databaseName == null)
{
throw new ArgumentNullException("databaseName");
}
if (databaseName == "admin" && credentials != null && !credentials.Admin)
{
throw new ArgumentOutOfRangeException("Credentials for the admin database must have the admin flag set to true.");
}
if (readPreference == null)
{
throw new ArgumentNullException("readPreference");
}
if (safeMode == null)
{
throw new ArgumentNullException("safeMode");
}
_databaseName = databaseName;
_credentials = credentials;
_guidRepresentation = guidRepresentation;
_readPreference = readPreference;
_safeMode = safeMode;
}
示例7: CreatDataBase
static MongoDatabase CreatDataBase(string bdName, string userName, string userPw)
{
var mongoUrlBuilder = new MongoUrlBuilder("mongodb://localhost");
MongoServer server = MongoServer.Create(mongoUrlBuilder.ToMongoUrl());
MongoCredentials credentials = new MongoCredentials(userName, userPw);
MongoDatabase database = server.GetDatabase(bdName, credentials);
return database;
}
示例8: MongoUser
/// <summary>
/// Creates a new instance of MongoUser.
/// </summary>
/// <param name="credentials">The user's credentials.</param>
/// <param name="isReadOnly">Whether the user has read-only access.</param>
public MongoUser(
MongoCredentials credentials,
bool isReadOnly
) {
this.username = credentials.Username;
this.passwordHash = HashPassword(credentials.Username, credentials.Password);
this.isReadOnly = isReadOnly;
}
示例9: MongoDatabaseSettings
/// <summary>
/// Creates a new instance of MongoDatabaseSettings.
/// </summary>
/// <param name="databaseName">The name of the database.</param>
/// <param name="credentials">The credentials to access the database.</param>
/// <param name="guidRepresentation">The representation for Guids.</param>
/// <param name="safeMode">The safe mode to use.</param>
/// <param name="slaveOk">Whether queries should be sent to secondary servers.</param>
public MongoDatabaseSettings(string databaseName, MongoCredentials credentials, GuidRepresentation guidRepresentation, SafeMode safeMode, bool slaveOk)
{
_databaseName = databaseName;
_credentials = credentials;
_guidRepresentation = guidRepresentation;
_safeMode = safeMode;
_slaveOk = slaveOk;
}
示例10: MongoDatabaseSettings
/// <summary>
/// Creates a new instance of MongoDatabaseSettings.
/// </summary>
/// <param name="databaseName">The name of the database.</param>
/// <param name="credentials">The credentials to access the database.</param>
/// <param name="guidRepresentation">The representation for Guids.</param>
/// <param name="safeMode">The safe mode to use.</param>
/// <param name="slaveOk">Whether queries should be sent to secondary servers.</param>
public MongoDatabaseSettings(string databaseName, MongoCredentials credentials, GuidRepresentation guidRepresentation, SafeMode safeMode, ReadPreference readPreference)
{
this.databaseName = databaseName;
this.credentials = credentials;
this.guidRepresentation = guidRepresentation;
this.safeMode = safeMode;
this.readPreference = readPreference;
}
示例11: AddUserToDB
/// <summary>
/// 添加用户
/// </summary>
/// <param name="strDBPath">数据库路径</param>
/// <param name="strUser">用户名</param>
/// <param name="password">密码</param>
/// <param name="isReadOnly">是否为只读</param>
public static void AddUserToDB(string strDBPath, string strUser, string password, bool isReadOnly)
{
MongoDatabase mongoDB = GetMongoDBBySvrPath(strDBPath);
MongoCredentials newUser = new MongoCredentials(strUser, password, false);
if (mongoDB.FindUser(strUser) == null)
{
mongoDB.AddUser(newUser,isReadOnly);
}
}
示例12: AddUserToDB
/// <summary>
/// Add User
/// </summary>
/// <param name="strUser">Username</param>
/// <param name="password">Password</param>
/// <param name="isReadOnly">Is ReadOnly</param>
public static void AddUserToDB(String strUser, String password, Boolean isReadOnly)
{
MongoDatabase mongoDB = SystemManager.GetCurrentDataBase();
MongoCredentials newUser = new MongoCredentials(strUser, password, false);
if (mongoDB.FindUser(strUser) == null)
{
mongoDB.AddUser(newUser, isReadOnly);
}
}
示例13: AddUserToSvr
/// <summary>
/// 添加User到Admin数据库[效果如同添加USER到整个服务器]
/// </summary>
/// <param name="strDBPath"></param>
/// <param name="strUser"></param>
/// <param name="password"></param>
/// <param name="isReadOnly"></param>
public static void AddUserToSvr(string strDBPath, string strUser, string password, bool isReadOnly)
{
MongoServer mongoSvr = SystemManager.GetCurrentService();
//必须使用MongoCredentials来添加用户不然的话,Password将使用明文登入到数据库中!
//这样的话,在使用MongoCredentials登入的时候,会发生密码错误引发的认证失败
MongoCredentials newUser = new MongoCredentials(strUser, password,true);
if (mongoSvr.AdminDatabase.FindUser(strUser) == null)
{
mongoSvr.AdminDatabase.AddUser(newUser,isReadOnly);
}
}
示例14: AddUserToSvr
//这里有个漏洞,对于数据库来说,对于local的验证和对于admin的验证是相同的。
//如果是加入用户到服务器中,是加入到local还是admin,需要考虑一下。
/// <summary>
/// Add A User to Admin database
/// </summary>
/// <param name="strUser">Username</param>
/// <param name="password">Password</param>
/// <param name="isReadOnly">Is ReadOnly</param>
public static void AddUserToSvr(String strUser, String password, Boolean isReadOnly)
{
MongoServer mongoSvr = SystemManager.GetCurrentServer();
//必须使用MongoCredentials来添加用户不然的话,Password将使用明文登入到数据库中!
//这样的话,在使用MongoCredentials登入的时候,会发生密码错误引发的认证失败
MongoCredentials newUser = new MongoCredentials(strUser, password, true);
if (mongoSvr.GetDatabase(DATABASE_NAME_ADMIN).FindUser(strUser) == null)
{
mongoSvr.GetDatabase(DATABASE_NAME_ADMIN).AddUser(newUser, isReadOnly);
}
}
示例15: MongoDatabaseSettings
/// <summary>
/// Creates a new instance of MongoDatabaseSettings. Usually you would call MongoServer.CreateDatabaseSettings instead.
/// </summary>
/// <param name="databaseName">The name of the database.</param>
/// <param name="credentials">The credentials to access the database.</param>
/// <param name="safeMode">The safe mode to use.</param>
/// <param name="slaveOk">Whether queries should be sent to secondary servers.</param>
public MongoDatabaseSettings(
string databaseName,
MongoCredentials credentials,
SafeMode safeMode,
bool slaveOk
) {
this.databaseName = databaseName;
this.credentials = credentials;
this.safeMode = safeMode;
this.slaveOk = slaveOk;
}