cloudant
Batch processing is a method of running high-volume, repetitive data jobs and it drives many actions behind the scenes. This includes applying updates, processing data, integrating data from multiple sources, data extraction, and many more. In this article, we will discuss how to write a batch process for the Cloudant NoSQL database using nodejs.
乙 ATCH处理运行大批量,重复数据作业的方法,它驱动幕后许多行动。 这包括应用更新,处理数据,集成来自多个来源的数据,数据提取等等。 在本文中,我们将讨论如何使用nodejs为Cloudant NoSQL数据库编写批处理。
nodejs use an event-driven, asynchronous non-blocking I/O model. So, considering a scenario where thousands or even millions of records need to be processed or updated, it could impact database performance as it would almost simultaneously fire all the calls at once. In this article, we will discuss the ways to address this issue using nodejs synchronous mechanism along with Cloudant bulk API.
nodejs使用事件驱动的异步非阻塞I / O模型。 因此,考虑到需要处理或更新成千上万条记录的情况,这可能会影响数据库性能,因为它将几乎同时触发所有调用。 在本文中,我们将讨论使用nodejs同步机制以及Cloudant批量API解决此问题的方法。
To demonstrate batch processing with an example lets replicate “movies-demo” database listed in examples.cloudant.com.
为了用示例演示批处理,让我们复制examples.cloudant.com中列出的“ movies-demo ”数据库。
Refer the example here to setup database replication
请在此处参考示例 设置数据库复制
情境 (Scenario)
For this article, we will use the “movies-demo” database and update all the documents which are older than the year 2000, with a new attribute Old_movie:true
using nodejs.
对于本文,我们将使用“电影演示”数据库并使用nodejs使用新属性Old_movie:true
更新2000年以前的所有文档。
脚步 (Steps)
- Create a view in the “movies-demo” Cloudant database to filter out the documents which are older than the year 2000. 在“电影演示” Cloudant数据库中创建一个视图,以过滤出早于2000年的文档。
Write a nodejs script to add a new attribute
Old_movie:true
in all these documents selected by the view, in a synchronized manner.编写一个nodejs脚本,以同步方式在视图选择的所有这些文档中添加新属性
Old_movie:true
。- Improvise the node scri