Tag: 模式

让所有的领域需要mongoose

mongoose似乎默认使所有的领域不需要。 有没有办法使所有的字段不需要改变: Dimension = mongoose.Schema( name: String value: String ) 至 Dimension = mongoose.Schema( name: type: String required: true value: type: String required: true ) 它会变得非常难看,因为我有很多这些。

mongoose:扩展模式

目前我有两个几乎相同的模式: var userSchema = mongoose.Schema({ email: {type: String, unique: true, required: true, validate: emailValidator}, passwordHash: {type: String, required: true}, firstname: {type: String, validate: firstnameValidator}, lastname: {type: String, validate: lastnameValidator}, phone: {type: String, validate: phoneValidator}, }); 和 var adminSchema = mongoose.Schema({ email: {type: String, unique: true, required: true, validate: emailValidator}, passwordHash: {type: String, required: true}, firstname: […]

mongoose模式可选字段

我有一个像这样在nodejs中有mongoose的用户模式 userschema = mongoose.Schema({ org: String, username: String, fullname: String, password: String, email: String }); 除了有时我需要添加更多的字段。 主要问题是:我可以在monogoose模式中有可选字段吗?

如何pipe理多个JSON模式文件?

我试图使用commonjs-utils中的node.js + json-schema.js来validation我的JSON API。 只是单一的validation很容易,但找不到正确的方式来pipe理多个模式文件以引用对方。 假设我有两个模型和两个API。 // book { "type": "object", "properties": { "title": { "type": "string" }, "author": { "type": "string" } } } // author { "type": "object", "properties": { "first_name": { "type": "string" }, "last_name": { "type": "string" } } } // authors API { "type": "array", "items": { "$ref": "author" } […]

如何用2d geo索引正确定义Mongoose模式中的数组对象

我目前在为下面的文档创build模式时遇到问题。 来自服务器的响应总是以“对象”的forms返回“trk”字段值。 不知何故,我不知道这应该如何工作,因为我至less尝试了所有对我有意义的方法;-) 如果这有帮助,我的Mongoose版本是3.6.20和MongoDB 2.4.7而在我忘记之前,它也将很好设置为索引(2d) 原始数据: { "_id": ObjectId("51ec4ac3eb7f7c701b000000"), "gpx": { "metadata": { "desc": "Nürburgring VLN-Variante", "country": "de", "isActive": true }, "trk": [ { "lat": 50.3299594, "lng": 6.9393006 }, { "lat": 50.3295046, "lng": 6.9390688 }, { "lat": 50.3293714, "lng": 6.9389939 }, { "lat": 50.3293284, "lng": 6.9389634 }] } } mongoose纲要: var TrackSchema = Schema({ _id: […]