Links

Insert Many

Inserts many documents
Use bulk insert when you want to insert many records into the database with one API call. This can be useful when you import data from any other sources.
post
https://api.codemash.io/
/{version}/db/{CollectionName}/bulk
[InsertMany] - Inserts many documents

Use bulk insert when you want to insert many records into database with one API call. This can be useful when you do import data from any other sources. https://docs.codemash.io/api/database/collections/insert-many

Parameters
No parameters
Responses
.NET
Node
PHP
var client = new CodeMashClient(apiKey, projectId);
var service = new CodeMashRepository<Person>(client);
var person1 = new Person { Name = "John" };
var person2 = new Person { Name = "Peter" };
var entities = new List<Person> { person1, person2 };
await service.InsertManyAsync(entities, new DatabaseInsertManyOptions());
Check the information about entities on how your class objects are serialized.
use Codemash\CodemashClient;
use Codemash\CodemashDb;
class CodemashService
{
protected CodemashDb $codemashDb;
protected string $collectionName = '{YOUR_COLLECTION_NAME}';
public function __construct()
{
$secretKey = '{YOUR_SECRET_KEY}';
$projectId = '{YOUR_PROJECT_ID}';
$client = new CodemashClient($secretKey, $projectId);
$this->codemashDb = new CodemashDb($client);
}
public function insertEmployees()
{
$employees = [];
$employees[] = ['name' => 'John', 'email' => '[email protected]', 'address' => 'New York'];
$employees[] = ['name' => 'Peter', 'email' => '[email protected]', 'address' => 'Los Angeles'];
$responseData = $this->codemashDb->insertMany([
'collectionName' => 'employees',
'documents' => $employees,
]);
}
}
Last modified 1yr ago