4

mongodb で連想配列を使用することは悪い習慣と見なされますか? なぜマングースがスキーマ定義でこれを提供していないように見えるのか、私は興味があります。

4

2 に答える 2

3

「連想配列」が「オブジェクト」を意味する場合、それは正常に機能します。通常の古い「オブジェクト」を使用するか、特定のプロパティを指定するか、「mongoose.Schema.Types.Mixed」を使用してさまざまなタイプを許可できます。

{
  //regular old javascript/json data types
  created: Date,
  //this works just fine
  statistics: Object,
  //or you can specify the shape of the object
  address: {state: String, line1: String},
  //for the extra features you get with a true subdocument
  nested: [SomeOtherMongooseSchema],
  //Could be array, boolean, number, whatever. Can vary with each document.
  grabBag: mongoose.Schema.Types.Mixed 
}
于 2013-10-02T19:29:10.020 に答える