skank
skank

Reputation: 91

MongoDB PHP library how to create database

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

Answers (2)

skank
skank

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

KiwiJuicer
KiwiJuicer

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

Related Questions