What is the output of this Mongoose code
4 phương ánCó giải thíchDễ
if validation fails? const mongoose = require('mongoose');
mongoose.connect('mongodb://localhost:27017/db');const schema =
new mongoose.Schema({
age: {
type: Number, min: 18
}
}); const Model =
mongoose.model('Model', schema);
async function run() {
try {
await Model.create({
age: 17
}
);
}
catch (err) {
console.log('Validation error');
}
}run();
Các phương án trả lời
Chọn một phương ánLời giảiChọn phương án để mở
Khi mã Mongoose gặp lỗi xác thực, nó sẽ tự động tạo ra một lỗi và dừng việc thực hiện. Trong trường hợp này, khi tạo một tài liệu với độ tuổi 17, Mongoose sẽ phát hiện ra rằng độ tuổi này không đáp ứng được yêu cầu tối thiểu là 18. Do đó, nó sẽ tạo ra một lỗi và in ra 'Validation error' lên console.
Cùng chương 5
Which of the following are true about the match option in the populate() method? (Choose 2 answers)Có lời giảiCâu hỏiWhich of the following are valid options for the populate() method in Mongoose? (Choose 2 answers)Có lời giảiCâu hỏiWhat are not use cases for Mongoose in Node.js?Có lời giảiCâu hỏiCả 34 câu của chủ đề34 câu