These are chat archives for Automattic/mongoose

Jan 2017
Pierry Bos
Jan 12 2017 05:04
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
Jan 12 2017 10:12

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

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);


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
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
Jan 12 2017 10:49
@EricMcRay I wish I could say I understand it
@EricMcRay but still kind of confusing
Erinç Fırtına
Jan 12 2017 11:11
@Lorengamboa I dont know how can I explain other than this :D
Lorenzo Gamboa García
Jan 12 2017 11:20
when should I use each one
i dont is there a more detailed example