Schemas And Models Flashcards

1
Q

What is a model?

A

It is the blueprint for a document to be stored in the database, similar to a class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a schema?

A

It is the rules that the model uses to create its blueprint for creating documents.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How do you create a schema?

A

const schema = new mongoose.Schema({attr: {type: String/Number/Date, default: val, required: [true, ‘error message’]}, attr: DataType});

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are some other important schema type options?

A

unique: true/false, trim: true/false

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which JavaScript built-in function gives the current date and time in milliseconds?

A

Date.now()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How do you set an attribute’s data as an array of data elements in a schema?

A

attr: [dataType]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

How do you create a model?

A

const ModelName = mongoose.model(‘ModelName’, Schema)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

When you create a new model, what happens in the background?

A

A new collection is created in the database named after the model.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly