Insert

Overview of collection insert methods

post
Insert One

https://api.codemash.io/:version/db/:collectionName
Inserts a new record to a particular collection.
Request
Response
Request
Path Parameters
version
required
string
A version of API endpoint.
collectionName
required
string
The name of collection to insert record to.
Headers
Authorization
required
string
Secret API key which belongs to your project or user. Not required if using cookies with session ID.
x-cm-projectid
required
string
Your project's ID. Can be passed as query parameter.
Body Parameters
document
required
string
Record to insert.
bypassDocumentValidation
optional
boolean
If set to true, document will not be validated against the schema.
waitForFileUpload
optional
boolean
If set to true, waits for files to be uploaded before returning from endpoint.
Response
200: OK
Returns inserted record in a string format. Here singular quotes are used to avoid escaping double quotes.
{
"result": "{ '_id': '5e37136bf59f3a3f940b99a4', 'name': 'John' }"
}
.NET
Node
.NET
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.

Node
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;
}

post
Insert Many

https://api.codemash.io/:version/db/:collectionName/bulk
Inserts multiple records to a particular collection.
Request
Response
Request
Path Parameters
version
required
string
A version of API endpoint.
collectionName
required
string
The name of collection to insert records to.
Headers
Authorization
required
string
Secret API key which belongs to your project or user. Not required if using cookies with session ID.
x-cm-projectid
required
string
Your project's ID. Can be passed as query parameter.
Body Parameters
documents
required
array
Array of records to insert. Each record is of string type.
bypassDocumentValidation
optional
boolean
If set to true, documents will not be validated against the schema.
Response
200: OK
Returns a list of IDs of newly inserted records in the order that was passed to insert them.
{
result: ["{RECORD_ID_1}", "{RECORD_ID_2}"]
}
.NET
Node
.NET
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.

Node