Reputation: 91
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?
Upvotes: 0
Views: 1399
Reputation: 91
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
Upvotes: 1
Reputation: 1972
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/
Upvotes: 1