【问题标题】:MongoDB update all users with stripe customer idMongoDB 使用条带客户 ID 更新所有用户
【发布时间】:2022-01-09 23:07:39
【问题描述】:

我有一个应用程序,它的 mongodb 集合中有超过 20,000 个用户。我刚刚在我的应用程序中实现了条带支付网关,现在我正在寻找一种最佳方式来运行每个用户,用条带注册他们,并将他们的客户 ID 保存在我的数据库中。

就上下文而言,当您在 stripe 中注册用户时,stripe 将为他们分配一个客户 ID。我想将此条带客户 ID 保存到我的用户对象/数据库中。

我当前的实现将自动注册新用户与条带,并保存条带客户 id 值,但是我需要对 20,000 多个用户进行改造。

我不确定解决此问题的最佳方法。如果是少量用户,我会编写一个脚本并执行Users.find() 之类的操作,然后映射每个用户,注册并更新它们。

非常感谢任何建议。

【问题讨论】:

  • 20,000 对这样的任务来说是一个相对较少的用户,我会完全按照你说的做,只需创建一个脚本;对于这项一次性任务,性能并不重要。

标签: javascript mongodb stripe-payments


【解决方案1】:
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.

现在有很多地方必须这样做,所以我的建议是为与条带相关的操作创建一条单独的路线。并为此使用 middelware 函数。

但是 20K 是一个很小的数字,而且是一次性操作。所以你应该使用脚本。

希望它会有所帮助:)

【讨论】:

    猜你喜欢
    • 2011-11-13
    • 1970-01-01
    • 1970-01-01
    • 2018-04-17
    • 1970-01-01
    • 1970-01-01
    • 2022-12-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多