Documentation Home
X DevAPI User Guide for MySQL Shell in JavaScript Mode
Download this Manual
PDF (US Ltr) - 1.2Mb
PDF (A4) - 1.2Mb


4.2.2 Working with Existing Collections

In order to retrieve a Collection object for an existing collection stored in the database call the getCollection() function from a Schema object.

// Get a collection object for 'my_collection'
var myColl = db.getCollection('my_collection');

The createCollection(), together with the ReuseExistingObject field set to true, can be used to create a new collection or reuse an existing collection with the given name. See Section 4.2.1, “Creating a Collection” for details.

Note

In most cases it is good practice to create database objects during development time and refrain from creating them on the fly during the production phase of a database project. Therefore it is best to separate the code that creates the collections in the database from the actual user application code.