Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

158
Visualizações
MongoDB update all users with stripe customer id

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.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

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

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda