I tried to find but I can't… Is there a way to ignore some properties of schema if Its value undefined, null or empty?For exampe I have:var SectionSchema = new Schema({caption: String,address: Number,counters: [Number],errors: {casset: [String],main: [String],dupl: [String]},warnings: {main: [String],dupl: [String]}});And several records in DB:== 1 ==
{caption: "One",address: 1001,error: {main: [ERR_CHN_A]}}
== 2 ==
{caption: "Two",address: 2002,counters: [24,24],warnings: {main: [SHIELD_DEV_B, SHIELD_DEV_C],
dupl: [SHIELD_DEV_B]
}}
As you can see records may contain not all properties of schema.And instead these records I recive:== 1 ==
{caption: "One",address: 1001,
counters: [],error: {
cassete: [],main: [ERR_CHN_A],
dupl: []},warnings: {main: [SHIELD_DEV_B, SHIELD_DEV_C],
dupl: [SHIELD_DEV_B]}}
== 2 =={caption: "Two",address: 2002,counters: [24,24],
errors: {
cassete: [],
main: [],
dupl: []
},warnings: {main: [SHIELD_DEV_B, SHIELD_DEV_C],
dupl: [SHIELD_DEV_B]}}
In ASP.NET WebAPI there is ignore conditions:public class SectionState{[BsonIgnoreIfNull]public string caption { get; set; }public int address { get; set; }[JsonProperty(NullValueHandling = NullValueHandling.Ignore)]public List<int> counters { get; set; }
[BsonIgnoreIfNull][JsonProperty(NullValueHandling = NullValueHandling.Ignore)]public EssoSectionErrors errors { get; set; }[BsonIgnoreIfNull][JsonProperty(NullValueHandling = NullValueHandling.Ignore)]public EssoSectionWarnings warnings { get; set; }}Is there something like this in Mongoose?--
--
http://mongoosejs.com - docs
http://plugins.mongoosejs.com - plugins search
http://github.com/learnboost/mongoose - source code
You received this message because you are subscribed to the Google
Groups "Mongoose Node.JS ORM" group.
To post to this group, send email to mongoo...@googlegroups.com
To unsubscribe from this group, send email to
mongoose-orm...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/mongoose-orm?hl=en
I play with schema.pre('save') and .toObject({ transform: true }) and see that mongoose doesn't insert missing in POST request fields of simple types (String, Number), but fields 'typeof' Array or Object are inserting with empty values. I think it's not quite right.
var schama = new Schema({
caption: String,
counters: [Number],
error: {
main: [String],
dupl: [String]
}
})
$.post(url, { counters: [2,2] });
/* Saved document
{
counters: [2,2],
error: {
main: [],
dupl: []
}
}
*/I think that if the field is missing in the POST request, it should not appear in the saved document.
четверг, 27 декабря 2012 г., 1:24:29 UTC+6 пользователь Aaron Heckmann написал:
mongoose-orm+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/mongoose-orm?hl=en
--
Aaron