Reputation: 63
I am trying to create a new database using mongo. (not a collection in the current database like the result of use "newDBname" ) Does anyone know how to do so?
An example in c# would be appreciated.
have a great day
Upvotes: 0
Views: 149
Reputation: 21
With mongoose ? If you're using mongoose, create a new schema for new collection.
After launch your backend, the new collection should be create.
Upvotes: 0
Reputation: 4857
according to doc, there is no such explicit operation/query, the database will be created implicitly when you will first time query to it if it wasn't created before. In c# it will be:
var database = client.GetDatabase("db_name"); // on this step, the server doesn't know that you want to create db_name
database.ListCollections(null, CancellationToken.None); // the database will be created only after running query, for example "ListCollections"
Upvotes: 1