I have an application that has just over 20,000 users in a mongodb collection. I've just implemented stripe payment gateway into my application, and now I'm looking for an optimal way to run through every user, register them with stripe, and save their customer id in my database.
For context, when you register a user in stripe, stripe will assign them a customer id. I would like to save this stripe customer id to my user object/database.
My current implementation will register new users with stripe automatically, and save the stripe customer id value, however I need to retrofit this to the 20,000+ users.
I'm not sure of the best way to approach this. If it was a small amount of users I would just write a script and do something like Users.find() and then map through every user, registering them, and updating them.
Any advice greatly appreciated.
Not sure if this would be a good idea. But here's my thought.
Since you're already registering each user on stripe and storing their stripe id on your side. You don't have to worry about new ones (just like you said).
Here's the steps:
1> Fetch user data.
2> Check if stripe customer id is there or not.
2.1> If it's there you can proceed with the stripe api operation that user
triggered.
2.2> If stripe customer id is not there then you can go ahead and register
the user on stripe. Store it in your DB and proceed with user request.
Though this will add an extra DB query.
Now there are a lot of places where you'll have to do this so my advice create a separate route for stripe related operations. And use a middelware function for this.
However 20K is a small number and it's a one time operation. So you should go with script.
Hopefully it'll help :)