Endpoint Create a document in the container
Name
create_document
Description
Insert JSON document in Cosmos DB Container. [API reference]
Related Tables
Parameters
Parameter | Required | Options | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
Name:
Label: Table Name (Case-Sensitive) |
YES | |||||||||
Name:
Label: Database Name (keep blank to use default) Case-Sensitive Leave blank to use default DB set on connection screen |
||||||||||
Name:
Label: Document |
||||||||||
Name:
Label: Partition Key Value (default is supplied Id) The partition key value for the document. Must be included if and only if the collection is created with a partitionKey definition |
|
|||||||||
Name:
Label: Enable Upsert Mode (update if document found) |
|
Output Columns
Label | Data Type (SSIS) | Data Type (SQL) | Length | Description |
---|---|---|---|---|
id |
DT_WSTR
|
nvarchar(4000)
|
4000 | |
_rid |
DT_WSTR
|
nvarchar(4000)
|
4000 | |
_ts |
DT_I8
|
bigint
|
||
http_status |
DT_I4
|
int
|
Input Columns
Label | Data Type (SSIS) | Data Type (SQL) | Length | Description |
---|---|---|---|---|
PartitionKey |
DT_WSTR
|
nvarchar(4000)
|
4000 | |
Document |
DT_NTEXT
|
nvarchar(MAX)
|
Examples
SSIS
Use Cosmos DB Connector in API Source or in API Destination SSIS Data Flow components to read or write data.
API Source
There are no parameters to configure. |

API Destination
This Endpoint belongs to the [Dynamic Table] table, therefore it is better to use it, instead of accessing the endpoint directly. Use this table and table-operation pair to create a document in the container:
There are no parameters to configure. |

ODBC application
Use these SQL queries in your ODBC application data source:
Create a new document with Partition Key supplied
Loads a new document into specified container with partition key. If you created container with Partition Key requirement then must supply it. Partition Key must be valid value from Document Attribute used as Partition Key.
INSERT INTO TestContainer (PartitionKey, Document)
VALUES(
'["user2"]', --partition key value must match its attribute from document else it will throw error. In this example container PartitionKey is /id so we used its value. For multiple key use JSON array ["val1","val2"]
'{
"id": "user2",
"name": "John Doe",
"email": "jdoe@contoso.com",
"phone": ["12345"],
"level": "platinum"
}'
)
WITH(Upsert='true')
Create a new document from a file path (Upload from local disk file)
Loads a new document into specified container from local file path. File path must start with @ symbol
INSERT INTO TestContainer (PartitionKey, Document)
VALUES(
'["user2"]', --partition key value must match its attribute from document else it will throw error. In this example container PartitionKey is /id so we used its value. For multiple key use JSON array ["val1","val2"]
'@c:\data\order.json' --path must start with @ symbol
)
WITH(Upsert='true', IsMultiPart=1)
Upsert a document (Insert or Update if exists)
Upsert a document (Update if id exists else create new one).
INSERT INTO TestContainer (PartitionKey, Document)
VALUES(
'["user2"]', --partition key value must match its attribute from document else it will throw error. In this example container PartitionKey is /id so we used its value. For multiple key use JSON array ["val1","val2"]
'{
"id": "user2",
"name": "John Doe",
"email": "jdoe@contoso.com",
"phone": ["12345"],
"level": "platinum"
}')
WITH(Upsert='true')
create_document
endpoint belongs to
[Dynamic Table]
table(s), and can therefore be used via those table(s).
SQL Server
Use these SQL queries in SQL Server after you create a data source in Data Gateway:
Create a new document with Partition Key supplied
Loads a new document into specified container with partition key. If you created container with Partition Key requirement then must supply it. Partition Key must be valid value from Document Attribute used as Partition Key.
DECLARE @MyQuery NVARCHAR(MAX) = 'INSERT INTO TestContainer (PartitionKey, Document)
VALUES(
''["user2"]'', --partition key value must match its attribute from document else it will throw error. In this example container PartitionKey is /id so we used its value. For multiple key use JSON array ["val1","val2"]
''{
"id": "user2",
"name": "John Doe",
"email": "jdoe@contoso.com",
"phone": ["12345"],
"level": "platinum"
}''
)
WITH(Upsert=''true'')';
EXEC (@MyQuery) AT [LS_TO_COSMOS_DB_IN_GATEWAY];
Create a new document from a file path (Upload from local disk file)
Loads a new document into specified container from local file path. File path must start with @ symbol
DECLARE @MyQuery NVARCHAR(MAX) = 'INSERT INTO TestContainer (PartitionKey, Document)
VALUES(
''["user2"]'', --partition key value must match its attribute from document else it will throw error. In this example container PartitionKey is /id so we used its value. For multiple key use JSON array ["val1","val2"]
''@c:\data\order.json'' --path must start with @ symbol
)
WITH(Upsert=''true'', IsMultiPart=1)';
EXEC (@MyQuery) AT [LS_TO_COSMOS_DB_IN_GATEWAY];
Upsert a document (Insert or Update if exists)
Upsert a document (Update if id exists else create new one).
DECLARE @MyQuery NVARCHAR(MAX) = 'INSERT INTO TestContainer (PartitionKey, Document)
VALUES(
''["user2"]'', --partition key value must match its attribute from document else it will throw error. In this example container PartitionKey is /id so we used its value. For multiple key use JSON array ["val1","val2"]
''{
"id": "user2",
"name": "John Doe",
"email": "jdoe@contoso.com",
"phone": ["12345"],
"level": "platinum"
}'')
WITH(Upsert=''true'')';
EXEC (@MyQuery) AT [LS_TO_COSMOS_DB_IN_GATEWAY];
create_document
endpoint belongs to
[Dynamic Table]
table(s), and can therefore be used via those table(s).