我试图让一个用户使用自定义 _id,其他用户使用默认值。
const userSchema = new mongoose.Schema({
_id: { type: String, default: mongoose.Types.ObjectId() },
password: String,
fName: String,
lName: String,
email: { type: String, unique: true, lowercase: true },
blogs: [blogSchema],
followers: Array,
followings: Array,
darkMode: Boolean,
});
自定义 id 有效,用户将 _id 作为字符串。
但其他值类型也是字符串而不是 ObjectId。
是否可以将此默认_id 转换为 ObjectId?
或者如果我把它留成字符串会有什么问题吗?