I use MongoDB PHP library in the client object I can see the method for drop a database, how can I create a new database?
2 Answers
You probably have problems with the naming.
In mongodb a DB is called an Index and a tabe called a Collection.
You will find createIndex in the docs:
http://mongodb.github.io/mongo-php-library/api/namespace-MongoDB.Operation.html
https://docs.mongodb.org/v3.0/reference/method/db.collection.createIndex/
Comments
the namespace database is automatically create if it does not exist when we create collection
use MongoDB\Driver\Manager;
use MongoDB\Database;
$manager = new Manager("mongodb://localhost:27017");
$database = new Database($manager, 'newDataBase');
var_dump($database->createCollection('CollectionName'));
sorry i keep learning
1 Comment
Máxima Alekz
Yes, the only way to "create a database" is to use an "x_database" and create a collection, and then database is created :) +1