简体   繁体   English

MongoDB 使用条带客户 ID 更新所有用户

[英]MongoDB update all users with stripe customer id

I have an application that has just over 20,000 users in a mongodb collection.我有一个应用程序,在 mongodb 集合中拥有超过 20,000 个用户。 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.我刚刚在我的应用程序中实现了条带支付网关,现在我正在寻找一种最佳方式来运行每个用户,用条带注册他们,并将他们的客户 ID 保存在我的数据库中。

For context, when you register a user in stripe, stripe will assign them a customer id.对于上下文,当您在条带中注册用户时,条带将为他们分配一个客户 ID。 I would like to save this stripe customer id to my user object/database.我想将此条带客户 ID 保存到我的用户对象/数据库中。

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.我当前的实现将自动注册新用户与条带,并保存条带客户 id 值,但是我需要 retrofit 这给 20,000 多个用户。

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.如果是少量用户,我只需编写一个脚本并执行类似Users.find()之类的操作,然后通过每个用户执行 map,注册并更新它们。

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.并为此使用中间件 function。

However 20K is a small number and it's a one time operation.然而 20K 是一个很小的数字,它是一次性操作。 So you should go with script.所以你应该用脚本 go 。

Hopefully it'll help:)希望它会有所帮助:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM