Edit data store records
Before you begin
- Plan
- Included in Free, Pro and Team. How plans and limits work
- Role
- Viewer or higher to see and export records, Editor or higher to change records and Editor or higher to save and restore snapshots.
- You need
- A project; see Keep data between requests
The project’s Data store tab lists its data store collections. Each collection opens on a page of its own: the mocks that serve it, and its records as a table you can search, sort, filter and edit while clients call the project. Use it to set up test data by hand, to fix the one record a test needs, or to see what a mock wrote.
Find records
Section titled “Find records”-
Open the project’s Data store tab. Each collection shows its records, its size and the mocks that use it, under Endpoints.
-
Select a collection’s name. Its page lists its records, 50 to a page, with the key, the records’
idand their most frequent fields as columns. Data store above the collection’s name goes back to the list. -
To search, type in the search box and select Search. A record matches when its key or its JSON contains the text, ignoring case.
-
To sort, select a column’s name: once for ascending, again for descending, and a third time for the stored order. Hold Shift to add a second column to the sort.
-
To filter, select the filter button beside a column’s name, choose how to compare, such as equals or is greater than, enter a value and select Add filter. Range comparisons are offered for columns that hold numbers or dates.
Select the arrow at the start of a row to see the whole record. Columns chooses which fields the table shows; the choice is kept in this browser for each collection. Search, filters, sort and page are in the page’s address, so you can share a view as a link.
The table compares values as the storeQuery template helper does: numbers as numbers, other values as text, and a record without the field last. So when a mock lists the collection with storeQuery, the table shows what that endpoint answers. When such a list mock exists, Copy as a request copies the request that asks the endpoint for the same records, such as /products?price_gt=50&sort=-price, and names the fields it does not filter or sort by.
Add, change and remove a record
Section titled “Add, change and remove a record”-
On the collection’s page, select Add record.
-
Enter a Key of 1 to 256 bytes, or select Generate for a UUID.
-
Enter the record as JSON in Value. Any JSON value works; Format indents it. A record is at most 64 KB.
-
Select Save.
To change a record, select its Edit button, change the JSON and select Save. A key cannot change: to rename a record, select Duplicate in its row’s menu, give the copy the new key, then Delete the old one.
To change one field, focus its cell and press Enter, or double-tap it. A text, number, true/false or null field at the record’s top level opens for editing in place; the id and nested values do not. Press Enter or select the check button to save, and press Escape or select the cross button to cancel. The rest of the record is saved as stored.
When every record on the page has an id equal to its key, as a REST resource’s records do, the dialog says so and keeps the key and the record’s id the same while you type either one, so the record answers at the address its id names.
Delete several records
Section titled “Delete several records”Tick the rows to delete, or the box in the header to tick the whole page; when the search matches more than the page, Select all N matching takes every one of them. Select Delete in the bar above the table and confirm. The confirmation offers Save a snapshot first, ticked. A delete of every matching record is refused with Data store records changed when a mock changed how many match first, and then nothing is deleted.
When a mock changed the record first
Section titled “When a mock changed the record first”An edit is saved only over the version you opened. If a mock, a teammate or a script wrote the record in between, Save is refused with Data store record changed, and nothing is written. The dialog keeps your text and shows the record as it is now beside it:
- Overwrite with your text writes your text over the version you have just seen.
- Reload the record drops your text and starts again from the record as it is now.
When the page follows the store live, the dialog says the record changed as soon as it does, before you select Save. An edit in a cell is refused the same way: the cell keeps your text through a live update and says the record changed, and Save then reloads the table without writing. Deleting a record is refused the same way; the table then reloads, so you can look again. Adding a record never replaces one: a taken key is refused with Data store record exists, which the dialog says under Key.
Import and export records
Section titled “Import and export records”-
On the collection’s page, select Import in the More collection actions menu.
-
Paste records into Records, or select Choose a .json file. Either a collection’s export,
{"records": [{"key": …, "value": …}]}, or a JSON array of objects. -
For an array, enter the field each record’s key is read from in Key field; it starts as
id. An object without that field gets a generated UUID, written into the field. -
Choose Add to the collection or Replace the collection. Adding refuses the whole import when a key is taken, unless you tick Overwrite records whose key is taken.
-
Check the line under the choices, such as
Adds 40 records, 12 KB; the store then holds at most 46 of 1,000., and select Import.
Replace the collection asks first, naming how many records it removes. Export in the same menu downloads the collection as <collection>.json, in the shape an import reads back. One import takes at most 5,000 records.
To start a collection from records, select New collection on the Data store tab, enter a Collection name and the records, and select Create collection. A collection exists only while it holds a record, so a new one always starts with some.
Give a collection endpoints
Section titled “Give a collection endpoints”A collection that no mock serves shows Add REST endpoints. It opens New REST resource with the collection, its name and the path /<collection> filled in; see Build a REST resource that remembers. Once mocks serve the collection, its page lists them under Endpoints as Writes, Reads and Requires, and Show in Mocks opens the resource’s mocks on the Mocks tab.
Save and restore a snapshot
Section titled “Save and restore a snapshot”A snapshot is a named fixture of the store, so the CLI, an AI assistant and a CI pipeline can apply it too. Snapshots are on Free, Pro and Team.
-
On a collection’s page, select Snapshots in the More collection actions menu. On the Data store tab, Snapshots covers the whole store.
-
Enter a name, or keep the one offered, and select Save snapshot. A name another snapshot has cannot be saved again.
-
To put records back, select Restore on a snapshot and confirm; the dialog then closes on the restored records. From a collection’s page, it replaces that collection’s records with the snapshot’s and touches nothing else. On the Data store tab, Restore everything replaces the whole store and puts every scenario back in its saved state, and a collection’s button under Restore one collection replaces only that one.
Reset to a snapshot
Section titled “Reset to a snapshot”Reset, beside a page’s actions, puts records back in one step once a snapshot exists. With one snapshot it asks to restore that one, naming its age and what it replaces. With several it lists them, newest first with their record counts; the one you reset to last in this browser comes first. On the Data store tab it replaces the whole store and puts every scenario back in its saved state; on a collection’s page it lists only the snapshots holding that collection and replaces only its records. If the snapshot changed since the list was read, nothing is restored and the list is read again.
To rename a snapshot, select its pencil button, type the new name and select Rename, or Cancel to keep the name. A name another fixture of the project has cannot be used, and when the snapshot changed after the list was read, nothing is renamed and the list is read again.
Clear, Replace the collection and Restore each offer Save a snapshot first, ticked, in their confirmation. The snapshot is taken before the action, and when it cannot be saved the action does not run. Nothing takes a snapshot without asking.
Follow the store live
Section titled “Follow the store live”While both pages show Live, they re-read on their own when a mock writes the store or someone changes a record: the table keeps its search, filters and sort, and rows that were added or changed are highlighted for two seconds. Refresh is then in the page’s menu. Where Live is not shown, select Refresh to see new writes.
From the CLI and the API
Section titled “From the CLI and the API”mockhub store get, store put, store delete, store export and store import do the same from a terminal or a pipeline, and fixture capture and fixture apply take --collection for a snapshot of one collection; see the CLI reference. An edit through the API sends the record’s etag as If-Match, as the dashboard does.
Limits
Section titled “Limits”- The store is test data. Edits are not audited and have no history: the only undo is a snapshot taken before.
- Two edits are never merged. The second is refused and its author chooses which one stays.
- Search, filters and sort scan the whole collection on every read. There are at most five filters and two sort fields, and no expressions or regular expressions.
- A snapshot counts towards the workspace’s configuration budget, is not taken automatically, and is not atomic: taken while requests write the store, it can hold some collections from before a write and others from after it.
- Live updates say that the store changed, not which record. A burst of writes arrives as one refresh, at most one a second, and a mock’s write can occasionally go unannounced until the next one; Refresh always reads the current records.
- Endpoints lists the mocks whose definitions name the collection. A mock that reaches it through a computed name is not listed, and one that names it only in a comment is.