1

I am performing CRUD operations using MEAN stack. I am using mongoose and I have created a schema also.

discussions.js

const mongoose = require('mongoose');
const Schema = mongoose.Schema;

const discussionSchema = new Schema({
  question: String,
  date: String,
  askedby: String,
  answers: String[],
  tags: String[]
})

module.exports = mongoose.model('discussion', discussionSchema, 'discussions');

Notice that answers and tags properties should be an array of string type while rest of the properties are simple string values. Is this the correct implementation? Please correct me.

1
  • 1
    String arrays in schemas can be defined as: answers: [String]. Mongoose schemas types Commented Sep 13, 2019 at 20:58

1 Answer 1

2

The correct way to define is :

  answers :[String],
  tags:[String]

or

answers :[{ type: String }],
tags:[{ type: String }]

Reference: https://mongoosejs.com/docs/schematypes.html

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.