title: Mongoose: Setting a new array of document references when updating a document
body: <p>I keep getting an error whenever I try to set a new array of document references. This causes an error saying: <strong>"Cannot read property '$isMongooseDocumentArray' of undefined";</strong>.
  How would I go about updating a document with an array of references to other documents from another schema. I'm trying to replace that array of document references with a new set.</p>
  
  <pre><code>Lets say I had this schema with a particular reference:
  
  const userCommandSchema = mongo.Schema({
    objectID: mongo.Schema.ObjectId,
    userID: { type: String, required: true },
    command: { type: String, required: true },
    summary: { type: String },
    isFavourite: { type: Boolean, default: false },
  },
  { timestamps: true }
  );
  
  const UserCommandSequenceSchema = mongo.Schema({
    objectID: mongo.Schema.ObjectId,
    userID: { type: String, required: true },
    commandSequenceTitle: { type: String, required: true },
    commandSequenceDescription: { type: String, required: false },
    commands: [{ type: mongo.Schema.Types.ObjectId, ref: 'UserCommand' }],
  },
  { timestamps: true }
  );
  
  
  // How would I go about updating an array of document references?
  
  const arrayOfObjectIDs = [mongo.Types.ObjectId("57d2e31f0098c69c4eefde53"), mongo.Types.ObjectId("57d2e31f0098c69c4eefde57")];
  
  const query = { _id: id };
  
  const update = { $set: {
    commandSequenceTitle,
    commandSequenceDescription,
    commands
  },
  };
  
  const options = { new: true };
  
  UserCommandModel.findOneAndUpdate(query, update, options)
  .exec()
  .then(({ _id, commandSequenceTitle, commandSequenceDescription, commands, createdAt, updatedAt }) =&gt; {
  })
  .catch((err) =&gt; {
    console.log(err);
  });
  </code></pre>