solaire
solaire

Reputation: 505

Default with Date not working with Mongoose

I have the following data model:

overall_stats: {
        elo: {
            type: Array,
            default: {
                date: Date.now,
                ranking: 1000,
            }
        },
 ....

If I put a number instead of Date.now it works but like that it doesn't. I assume its because the field is not declared as a date. However I tried a lot of different options to declare it but never got the syntax right.

Upvotes: 2

Views: 1277

Answers (1)

Cuong Le Ngoc
Cuong Le Ngoc

Reputation: 11975

Date.now is a function so to make it work, you need to put Date.now() or if you want a date instead of a number then new Date() will help:

overall_stats: {
    elo: {
        type: Array,
        default: {
            date: new Date(),
            ranking: 1000,
        }
    },
....

Upvotes: 3

Related Questions