PDF (美式信紙) - 1.4Mb
PDF (A4) - 1.4Mb
為了建立新的集合,請從綱要物件呼叫 createCollection()
函數。它會傳回一個集合物件,該物件可以立即用來將文件插入資料庫等等。
選擇性地,對於連接器,可以將欄位 reuseExistingObject
設定為 true 並作為第二個參數傳遞,以防止在已存在具有相同名稱的集合時產生錯誤。
MySQL Shell JavaScript 程式碼
// Create a new collection called 'my_collection'
var myColl = db.createCollection('my_collection');
MySQL Shell Python 程式碼
# Create a new collection called 'my_collection'
myColl = db.create_collection('my_collection')
Node.js JavaScript 程式碼
// 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# 程式碼
// 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 程式碼
# 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 程式碼
// 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++ 程式碼
// 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);