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
CodePudding user response:
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"
CodePudding user response:
With mongoose ? If you're using mongoose, create a new schema for new collection.
After launch your backend, the new collection should be create.