0
私の文書には小文字のフィールドをいくつか保存したい。したがって、私は値を挿入するsave()
を使用していたとき、私はfindOneAndUpdate()の実行中にMongooseの小文字のフラグが無視される
let body = new Schema({
id: { type: Number, unique: true },
group_name: { type: String, lowercase: true },
type_name: { type: String, lowercase: true },
full_spectral_class: { type: String, lowercase: true },
spectral_class: { type: String, lowercase: true },
spectral_sub_class: { type: String, lowercase: true },
luminosity_class: { type: String, lowercase: true },
luminosity_sub_class: { type: String, lowercase: true }
})
のようなスキーマを作成し、すべての値は小文字の文字列として保存されてきています。しかし、私がfindOneAndUpdate()
を使って更新しようとしたとき、その値はそのままです。私はむしろ、同じスタイルに従ったかなりの数のフィールドとスキーマがあるので、すべてのフィールドを手動で小文字に変換しません。
あなたはおそらく、[クエリを実行するときに 'true'に' runSettersOnQuery']を設定する必要があります(http://mongoosejs.com/docs/api.html#model_Model.findOneAndUpdate)。 – str
それはちょっと働いた。 'schema.findOneAndUpdate(query、config)'で 'runSettersOnQuery:true'を使用しても動作しませんでした。スキーマを[ここ](http://mongoosejs.com/docs/queries.html)として定義しながら、オプションとして使用しなければなりませんでした。 –