0

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 2

1

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/

Sign up to request clarification or add additional context in comments.

Comments

1

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

Yes, the only way to "create a database" is to use an "x_database" and create a collection, and then database is created :) +1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.