What I am trying to do is creating a proper schema declaration in mongoose
for a given json document.
{
"_id": "1",
"nation": "at",
"type": "plot",
"comparables":[{
"properties":[{
"state":0,
"name":"flaeche",
"type":"Number",
"value":"100"
},
{
"state":1,
"name":"preis",
"type":"Number",
"value":"1234.12"}
]
},
{
"properties":[{
"state":0,
"name":"flaeche",
"type":"Number",
"value":"100"
},
{
"state":1,
"name":"preis",
"type":"Number",
"value":"1234.12"}
]
}]
}
// this is my schema ... which does not work as desired...
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
var PropertiesSchema = new Schema ( {
state: { type: Number, min: 0, max:1 },
name: { type: String, lowercase: true },
type: { type: String, lowercase: true },
value: String
});
var ComparablesSchema = new Schema ( {
properties: [ PropertiesSchema ]
});
var VPSchema = new Schema({
_id: {type: String, unique:true},
type: { type: String, lowercase: true },
nation: { type: String, lowercase: true },
comparables: [ ComparablesSchema ]
}, {_id: false});
module.exports = mongoose.model('VP', VPSchema, 'vp');
Does anyone see the obvious? Thank you for your help
and best regards, Günther
It would help a lot if you explained what is going wrong. “Does not work as desired” is too vague to help. What did you expect to see under what circumstance, and what did you see instead?
Well, thanks Jason...
The error I am getting when I post the document is:
if (key) this.setValue(key, delta[key] = 0);
^
TypeError: Cannot set property '__v' of undefined
I've tried to disable it on the sub-doc's level ({ versionKey: false }),
but without success.
Well, I found the reason why I've got this strange error
message.
This message occurs every time a sub-doc is null. In
my case is was 'comparables'.
댓글 없음:
댓글 쓰기