1

I have a field, which doesn't get added on the first save of the document, but its eventually changed later. But this is causing an error because if I don't start it off with a value it defaults to nothing. And since the field is suppose to be unique, two values can both be nothing.

How do I work around this?

I'm making a reference to a twitterAccount, and I save it before having the access_token and access_secret which will be unique but I need to save the request_token and request_secret before that so I can retrieve them in order to get the access_token and access_secret

const twitterAccountSchema = new Schema({
    _user: { type: String, unique: false, require: true, ref: 'User'},
    twitter_id: { type: String, unique: true, require: false },
    request_token: { type: String, unique: true, require: false },
    request_secret: { type: String, unique: true, require: false },

    // these dont get added on the initial .save()
    access_token: { type: String, unique: true, require: false },
    access_secret: { type: String, unique: true, require: false },


    date_created : { type: Date, default: Date.now, required: true },
    date_updated : { type: Date, default: Date.now, required: true },
});
joe
  • 1,563
  • 4
  • 16
  • 35

0 Answers0