PDF (US Ltr)
- 1.4Mb
PDF (A4)
- 1.4Mb
In order to create a new collection call the
createCollection()
function from a Schema
object. It returns a Collection object that can be used right
away to, for example, insert documents into the database.
Optionally, for Connectors, the field
reuseExistingObject
can be set to true and
passed as second parameter to prevent an error being generated
if a collection with the same name already exists.
MySQL Shell JavaScript Code
Press CTRL+C to copy// Create a new collection called 'my_collection' var myColl = db.createCollection('my_collection');
MySQL Shell Python Code
Press CTRL+C to copy# Create a new collection called 'my_collection' myColl = db.create_collection('my_collection')
Node.js JavaScript Code
Press CTRL+C to copy// Create a new collection called 'my_collection' var promise = db.createCollection('my_collection'); // Create a new collection or reuse existing one var promise = db.createCollection('my_collection', { ReuseExistingObject: true } );
C# Code
Press CTRL+C to copy// Create a new collection called "my_collection" var myColl = db.CreateCollection("my_collection"); // Create a new collection or reuse existing one var myExistingColl = db.CreateCollection("my_collection", ReuseExistingObject: true);
Python Code
Press CTRL+C to copy# Create a new collection called 'my_collection' my_coll = my_schema.create_collection('my_collection') # Create a new collection or reuse existing one my_coll = my_schema.create_collection('my_collection', True)
Java Code
Press CTRL+C to copy// Create a new collection called 'my_collection' Collection myColl = db.createCollection("my_collection"); // Create a new collection or reuse existing one // Second parameter is: boolean reuseExistingObject Collection myExistingColl = db.createCollection("my_collection", true);
C++ Code
Press CTRL+C to copy// Create a new collection called 'my_collection' Collection myColl = db.createCollection("my_collection"); // Create a new collection or reuse existing one Collection myExistingColl = db.createCollection("my_collection", true);