Your Mirage server has a database which you can interact with in your route handlers. You’ll typically use models to interact with your database data, but you can always reach into the db directly in the event you want more control.

Access the db from your route handlers via schema.db.

You can access individual DbCollections by using schema.db.name:

schema.db.users  // would return, e.g., [ { id: 1, name: 'Yehuda' }, { id: 2, name: 'Tom '} ]


createCollection(name: any, initialData: any): any

Add an empty collection named name to your database. Typically you won’t need to do this yourself, since collections are automatically created for any models you have defined.

dump(): any

Logs out the contents of the Db.

server.db.dump() // { users: [ name: 'Yehuda', ...

emptyData(): any

Removes all data from Mirage's database.

loadData(data: Object): any

Loads an object of data into Mirage's database.

The keys of the object correspond to the DbCollections, and the values are arrays of records.

  users: [
    { name: 'Yehuda' },
    { name: 'Tom' }

As with db.collection.insert, IDs will automatically be created for records that don't have them.