In MySQL Shell, you can create new collections, get a list of the existing collections in a schema, and remove an existing collection from a schema. Collection names are case-sensitive and each collection name must be unique.
To show the value that is assigned to the schema variable,
mysql-js> db <Schema:world_x>
If the schema value is not
then set the
db variable as follows:
mysql-js> \use world_x Schema `world_x` accessible through db.
To create a new collection in an existing schema, use the
The following example creates in the
world_x database a collection called flags.
The method returns a collection object.
mysql-js> db.createCollection("flags") <Collection:flags>
To display all collections in the
database, use the
on the schema object. Collections returned by the server
appear between brackets.
mysql-js> db.getCollections() [ <Collection:countryinfo>, <Collection:flags> ]
To drop an existing collection from a database, use the
dropCollection() method on the session
object. For example, to drop the flags collection from the
world_x database, type:
mysql-js> session.dropCollection("world_x", "flags") Query OK (0.04 sec)
See Collection Objects for more examples.