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.

Tanzeel
  • 4,174
  • 13
  • 57
  • 110
  • 1
    `String` arrays in schemas can be defined as: `answers: [String]`. [Mongoose schemas types](https://mongoosejs.com/docs/schematypes.html#arrays) – ambianBeing Sep 13 '19 at 20:58

1 Answers1

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

Kousika Ganesan
  • 539
  • 1
  • 6
  • 22