Saturday, 18 July 2020

How to create Mongoose field with array that's initialized.

For a project I'm working on, I want to create a chat mongoose schema, and within the chat schema there is a users field that consists of an array with type String, and required is set to true. The code for that field looks like the code below.​ users: { type: [String], required: true }, However, what do I do if I want to initialize the users array with a value with a single user at the beginning? Thanks for any help in advance!

Submitted July 18, 2020 at 11:27PM by dwight12345

No comments:

Post a Comment