Hi Robert,
Thanks for the reply. I have ran into some issues with the suggested
approach that I would like to share with you. So, just to recap:
I want to create a new database and then a new collection in that
database.
Here is what I am doing in code to achieve the above:
// Connect to server
var url = "mongodb://someAdminUser:someAdminUserPassword@localhost:
9001/admin"
var server = MongoServer.Create(url);
// Create my new database
var db = server.GetDatabase("SomeNewDatabase");
// Create my new collection
var collection = db.CreateCollection("MyNewCollection");
Observations:
I am running in authenticated mode but the database has not been
create yet, therefore, has no user credentials to authenticate against
Questions:
1. Given that I am running in authenticated mode what is the proper
way to connect to the server so that I can create a database that at
creation will not have any credentials? (please see the below error
message I am getting when executing the above code sample)
2. Is there a way to create a database without writing any data like
you would in SQL Server? I am currently doing this from the mongo
shell in PowerShell using connect("MyNewDatabase"). I would be willing
to write a CreateDatabase method if you can provide guidance.
Invalid credentials for database 'SomeTestDatabase'.
at MongoDB.Driver.Internal.MongoConnection.Authenticate(String
databaseName, MongoCredentials credentials) in C:\work\10gen\mongodb
\mongo-csharp-driver\Driver\Internal\MongoConnection.cs:line 165
at
MongoDB.Driver.Internal.MongoConnection.CheckAuthentication(MongoDatabase
database) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Internal
\MongoConnection.cs:line 244
at
MongoDB.Driver.MongoServerInstance.AcquireConnection(MongoDatabase
database) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver\Core
\MongoServerInstance.cs:line 260
at MongoDB.Driver.MongoServer.AcquireConnection(MongoDatabase
database, Boolean slaveOk) in C:\work\10gen\mongodb\mongo-csharp-driver
\Driver\Core\MongoServer.cs:line 1052
at MongoDB.Driver.MongoCursorEnumerator`1.AcquireConnection() in C:
\work\10gen\mongodb\mongo-csharp-driver\Driver\Core
\MongoCursorEnumerator.cs:line 184
at MongoDB.Driver.MongoCursorEnumerator`1.GetFirst() in C:\work
\10gen\mongodb\mongo-csharp-driver\Driver\Core
\MongoCursorEnumerator.cs:line 194
at MongoDB.Driver.MongoCursorEnumerator`1.MoveNext() in C:\work
\10gen\mongodb\mongo-csharp-driver\Driver\Core
\MongoCursorEnumerator.cs:line 126
at MongoDB.Driver.MongoDatabase.GetCollectionNames() in C:\work
\10gen\mongodb\mongo-csharp-driver\Driver\Core\MongoDatabase.cs:line
662
at MongoDB.Driver.MongoDatabase.CollectionExists(String
collectionName) in C:\work\10gen\mongodb\mongo-csharp-driver\Driver
\Core\MongoDatabase.cs:line 305
Thanks.
Best Regards,
RelayHealth
Albert L. Hives