我正在尝试编写一个节点程序,该程序采用数据流(使用 xml-stream)并将其合并并将其写入数据库(使用猫鼬)。我在弄清楚如何进行合并时遇到问题,因为在我处理下一条记录时数据可能还没有进入数据库。我正在尝试做类似的事情:
on order data being read from stream
look to see if customer exists on mongodb collection
if customer exists
add the order to the document
else
create the customer record with just this order
save the customer
我的问题是客户的两个“附近”订单导致写入重复的客户记录,因为在第二个检查是否存在之前没有写入第一个记录。
从理论上讲,我认为我可以通过暂停 xml 流来解决这个问题,但是有一个错误阻止我这样做。