Mutations
info
Unlike MongoDB and SQL services, create() and update() in ElasticCollectionService do not return the document. They return Elasticsearch response objects. Fetch the document separately with get() or findById() if needed.
create
Indexes a new document. Auto-generates an ID if _id is not included in the input.
const response = await svc.create({
name: 'Wireless Headphones',
category: 'electronics',
price: 149.99,
inStock: true,
});
// response.result === 'created'
// response._id — the generated or provided ID
Use replaceIfExists to overwrite an existing document with the same ID:
await svc.create(input, { replaceIfExists: true });
update
Applies a partial update to the document with the given ID. Only the fields you include are changed; everything else is untouched.
const response = await svc.update(id, { price: 129.99, inStock: false });
// response.updated === 1 (number of updated documents)
// response.total === 1
updateMany
Applies a partial update to all documents matching the filter.
const response = await svc.updateMany(
{ inStock: false },
{ filter: 'price < 10' },
);
// response.updated — number of updated documents
delete
Deletes the document with the given ID.
const response = await svc.delete(id);
// response.deleted === 1 (or 0 if not found)
deleteMany
Deletes all documents matching the filter.
const response = await svc.deleteMany({
filter: 'inStock = false',
});
// response.deleted — number of deleted documents