All code that accesses the database should be within this success callback. Currently you're checking for the error and continuing regardless.