I have following model in mongoose :
var RelationSchema = new Schema({
user : {type:ObjectId, ref:'users'}
, type : String
, remarks : String
, createdOn : {type:Date, default:Date.now}
}, {_id:false});
var UserRelationSchema = new Schema({
user : {type:ObjectId, ref:'users'}
, relations : [RelationSchema]
});
var UserRelation = mongoose.model('user_relations', UserRelationSchema);
Each time I run the following command with same values a new sub-document is being added to the relations
array. If I removed createdOn
field from the RelationSchema
schema then it works fine.
UserRelation.update(
{"user":<ObjectId>}
, {
$addToSet: {
"relations": {"user":<ObjectId>,"type":<String>}
}
, {upsert:true}
});
My Question is :
How can I addToSet
with date/time fields ?