Did you mean to do 

    var api = db.changes

here? api is undefined