私信  •  关注

Sergio Rodrigues

Sergio Rodrigues 最近创建的主题
Sergio Rodrigues 最近回复了
7 年前
回复了 Sergio Rodrigues 创建的主题 » GraphQL和MongoDB-“Cast to Array failed”和Array[duplicate]

默认情况下,如果架构中有一个键为“type”的对象,mongoose会将其解释为类型声明。

// Mongoose interprets this as 'loc is a String'
var schema = new Schema({ loc: { type: String, coordinates: [Number] } });

更改类型键:

var schema = new Schema({
  // Mongoose interpets this as 'loc is an object with 2 keys, type and coordinates'
  loc: { type: String, coordinates: [Number] },
  // Mongoose interprets this as 'name is a String'
  name: { $type: String }
}, { typeKey: '$type' }); // A '$type' key means this object is a type declaration

链接: http://mongoosejs.com/docs/guide.html#typeKey