Próbuję zapisać nowy dokument w mongodb z mangustą, ale dostaję ValidationError: Path 'email' is required., Path 'passwordHash' is required., Path 'username' is required.
mimo że dostarczam email, passwordHash i nazwę użytkownika.Mongoose: wymagana ścieżka błędu sprawdzania poprawności
Oto schemat użytkownika.
var userSchema = new schema({
_id: Number,
username: { type: String, required: true, unique: true },
passwordHash: { type: String, required: true },
email: { type: String, required: true },
admin: Boolean,
createdAt: Date,
updatedAt: Date,
accountType: String
});
W ten sposób tworzę i zapisuję obiekt użytkownika.
var newUser = new user({
/* We will set the username, email and password field to null because they will be set later. */
username: null,
passwordHash: null,
email: null,
admin: false
}, { _id: false });
/* Save the new user. */
newUser.save(function(err) {
if(err) {
console.log("Can't create new user: %s", err);
} else {
/* We succesfully saved the new user, so let's send back the user id. */
}
});
Więc dlaczego mangusta zwróci błąd sprawdzania poprawności, nie mogę używać null
wartość jako tymczasowy?
Cóż, nie wiem, gdzie ustawiasz adres e-mail newUsers, passwordHash i nazwę użytkownika. ustawiasz je na wartość null, a następnie próbujesz zapisać. –
Nie możesz tego zrobić? 'null' jest wartością. – 2trill2spill