ottoman version: 2.5.2
StringType enum option allows passing "undefined" and undefined.
It also sets the value to "undefined".
When constructing the document, undefined will be cast to "undefined".
When saving the document, "undefined" will pass the check here:
|
if (value !== 'undefined' && typeof this.enumValues !== 'undefined') { |
example:
import { connect, model, Schema } from "ottoman";
await connect({
bucketName: "travel-sample",
connectionString: "couchbase://localhost",
username: "Administrator",
password: "password",
});
const userSchema = new Schema({
gender: { type: String, enum: ["M", "F"] },
});
const User = model("User", userSchema, {
scopeName: "_default",
collectionName: "_default",
});
const a = new User({ gender: undefined });
await a.save();
console.log(a.gender === "undefined"); // got true, expected false
const aa = await User.findById(a.id);
console.log(aa.gender === "undefined"); // got true, expected false
const b = new User({ gender: "undefined" });
await b.save(); // passes, expected ValidationError
console.log(b.gender === "undefined"); // got true, expected false
const bb = await User.findById(b.id);
console.log(bb.gender === "undefined"); // got true, expected false
ottoman version: 2.5.2
StringType enum option allows passing
"undefined"andundefined.It also sets the value to
"undefined".When constructing the document,
undefinedwill be cast to"undefined".When saving the document,
"undefined"will pass the check here:node-ottoman/src/schema/types/string-type.ts
Line 262 in f205b2c
example: