O'Reilly logo

Express.js Blueprints by Ben Augarten, Marc Kuo, Eric Lin, Aidha Shaikh, Fabiano Pereira Soriani, Geoffrey Tisserand, Chiqing Zhang, Kan Zhang

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Schema design

Each player can simply be represented by a document with a single field for the name:

{ name: 'leo' }

User schema

We will use Mongoose for our data modeling. Let's start with designing our user schema. The schemas are placed in the models folder in the app. The following screenshot shows the folder structure. The schema will have one required field name, this is done by adding required: true to the name object in the schema.

User schema

To make querying a user by name fast, we can add an index to name. By default, only the _id field that MongoDB generates will be indexed. This means, to perform a search by name, the database will need to iterate over ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required