These are chat archives for Automattic/mongoose

12th
Jan 2017
Pierry Bos
@pierrybos
Jan 12 2017 05:04
@pierrybos
hi guys, somebody get this? a collection has this id: { _id: { $old: "232e3es...
i cant found any document talking about that "$old"
Erinç Fırtına
@EricMcRay
Jan 12 2017 10:12

@Lorengamboa statics binds directly on Model object, methods bind on document. For example;
Schema

var userSchema = new Schema({
username: String,
password String
});

userSchema.methods.validatePassword = function(password){
    return this.password === password; // this equals to document
};

userSchema.statics.getByUsername = function(username){
    return this.findOne({username: username}); // this equals to registered mongoose model
}

mongoose.model(‘User’, userSchema);

Usage

var User  = mongoose.model(‘User’);

User.getByUsername(‘username’).exec(function(err, user){ // getByUsername is static
    user.validatePassword(‘password’) // validatePassword is method
});
Erinç Fırtına
@EricMcRay
Jan 12 2017 10:20
@pierrybos $old is wrong it should be $oid. $oid operator cast value as mongo object id
Lorenzo Gamboa García
@Lorengamboa
Jan 12 2017 10:49
@EricMcRay I wish I could say I understand it
@EricMcRay but still kind of confusing
Erinç Fırtına
@EricMcRay
Jan 12 2017 11:11
@Lorengamboa I dont know how can I explain other than this :D
Lorenzo Gamboa García
@Lorengamboa
Jan 12 2017 11:20
when should I use each one
i dont is there a more detailed example