Mongoose ValidationError when there's no collection

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.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

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

Blogger: Contempo template have managed to get the posts to post in full but there is still a “snippet” of the post at the bottom of each full post