Insert
Inserts a single document
var client = new CodeMashClient(apiKey, projectId);
var service = new CodeMashRepository<Person>(client);
var person = new Person { Name = "John" };
await service.InsertOneAsync(person, new DatabaseInsertOneOptions());
Check the information about entities on how your class objects are serialized.
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' => 'john@example.com',
'address' => 'New York',
],
]);
}
}
Last updated