Wednesday, 19 April 2017

Mongoose delete array item by ttl with expire, but doesn't work

I created an Schema like this:

var user = new Schema(
        //Here are some uninteresting values like eg. name
        connection:[{
                mail:   String //also shorted
                loginTry: [{   //to prevent bruteforce to max-failed-login
                    date: {type: Date, default: Date.now, expires: '15m'} //<-
                }]
        }]
});

What should it do

I created a User-Schema, where login-tries stored by the connection. After successful login, i remove all login-trys. If the count of the connection-trys is over 5, the user can't login anymore.

What does it not

Mongodb created the index to the loginTry and I found the TTL at the index [in Robomongo called loginTry.date], but it doesn't remove the array-part after 15 minutes or anyone else.

Why not?

Every loginTry has an own _id, just like connection and the user.



via ich

No comments:

Post a Comment