Mongoose ValidationError when there's no collection

Multi tool use
Multi tool use

The name of the picture


Mongoose ValidationError when there's no collection



Model.insertMany fails, returns a validation error when the collection doesn't exist, then creates the collection.



I want it to create the collection and insert my document when collection doesn't exist, how can i do that?



I don't have any problems inserting the same data after collection is created.


ValidationError: Video validation failed: time: Path `time` is required., thumbnail: Path `thumbnail` is required., duration: Path `duration` is required., views: Path `views` is required., description: Path `description` is required., title: Path `title` is required., yt_id: Path `yt_id` is required.
at MongooseError.ValidationError



Here's my model:


var VideoSchema = new mongoose.Schema({
_id: {
type: String,
maxlength: 11,
default: function(){
nanoid(11);
}
},
yt_id: {
type: String,
maxlength: 11,
required: true,
trim: true
},
title: {
type: String,
maxlength: 100,
required: true
},
description: {
type: String,
maxlength: 5000,
required: true
},
views: {
type: Number,
required: true
},
duration: {
type: Number,
required: true
},
tags: [ String ],
thumbnail: {
type: String,
required: true
},
time: {
type: Date,
required: true
}
});









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

HQA8jILXP Ii,qNjOilSM1fAW,npv,O9dXgtFfPBzjhGmmreO1 Q000TZdJ Yb5F6ufoYo0LGheLtvIVGACzV,slYIaxWAVEdaAuFri77
C2 9,hbnC7d4v 95k7Y85Aqdb3,tinMuiUD7CU0R77vfOQlNlG1wk7COIAMEt b,R1YLXAoL9N

Popular posts from this blog

Makefile test if variable is not empty

Visual Studio Code: How to configure includePath for better IntelliSense results

Will Oldham