title: NodeJS/Mongoose schema array of ObjectId
body: <p>I am trying to implement an array of ObjectId inside a schema in Mongoose.
  I searched in internet and I found that this should work :</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>import mongoose from 'mongoose';
  import Schema from 'mongoose';
  
  const UserSchema = mongoose.Schema({
    nickName: {
      type: String,
      unique: true,
      required: true,
    },
    follows: [{
      type: Schema.Types.ObjectId, //HERE
      ref: 'User',
      default: []
    }],
  }, {
    strict: true,
  });
  
  const User = mongoose.model('User', UserSchema);
  export default User;</code></pre>
  </div>
  </div>
  </p>
  
  <p>or this </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>follows: {
            type: [Schema.Types.ObjectId], // HERE
            ref: 'User',
            default: []
    },</code></pre>
  </div>
  </div>
  </p>
  
  <p>I know they are not exactly the same, but instead of working in both cases I have this error :</p>
  
  <pre><code> Invalid schema configuration: `ObjectID` is not a valid type within the array `follows`.
  </code></pre>
  
  <p>I don't know why is he telling my that ObjectID (with capital "ID") is not valid as I didn't declare any of this.</p>
  
  <p>How can I do an array of objectId ?
  I want an array of ObjectId by reference of the schema "User" with the people an user follow</p>
  
  <p>[<strong>EDIT</strong>]
  As Bhanu Sengar mentionned in the comment, I had to put "mongoose" before the Schema.</p>
  
  <pre><code>[{ type: mongoose.Schema.Types.ObjectId, ref: 'User' }] 
  </code></pre>
  
  <p>As Halil SAFAK said, I deleted the default value.</p>
  
  <p>It also didn't work because I had conflicts between the two imports</p>
  
  <pre><code>import mongoose from 'mongoose';
  import Schema from 'mongoose';
  </code></pre>