Insert
Inserts a single document
post
https://api.codemash.io/
/{version}/db/{CollectionName}
[InsertOne] - Inserts a single document
Inserts a new document into database. https://docs.codemash.io/api/database/collections/insert
Parameters
No parameters
Responses
.NET
Node
PHP
var client = new CodeMashClient(apiKey, projectId);
var service = new CodeMashRepository<Person>(client);
var person = new Person { Name = "John" };
await service.InsertOneAsync(person, new DatabaseInsertOneOptions());
import { db } from 'codemash';
const request = {
start: '1588855312059', // Unix time stamp in miliseconds
end: '1588855340191', // Unix time stamp in miliseconds
employee: 'some_user_id',
type: 'paid',
};
export async function saveHolidaysRequest(request) {
const response = await db.saveRecord('holidays', request);
return response;
}
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 insertEmployee()
{
$responseData = $this->codemashDb->insertOne([
'collectionName' => 'employees',
'document' => [
'name' => 'John',
'email' => '[email protected]',
'address' => 'New York',
],
]);
}
}
Last modified 9mo ago