mongodb atlas_如何使用MongoDB Stitch集成MongoDB Atlas和Segment

本文详细介绍了如何使用MongoDB Stitch将数据从Segment导入MongoDB Atlas,以便利用MongoDB的分析功能。首先在Segment设置工作区,然后将Segment添加到网站并发送事件。接着注册MongoDB Atlas并创建集群。使用MongoDB Stitch创建应用程序,实现从Segment到MongoDB Atlas的数据传输。通过Stitch函数验证请求并写入数据库。文章提供了逐步指南和代码示例,帮助读者在20分钟内完成集成。
摘要由CSDN通过智能技术生成

mongodb atlas

It can be quite difficult tying together multiple systems, APIs, and third-party services. Recently, we faced this exact problem in-house, when we wanted to get data from Segment into MongoDB so we could take advantage of MongoDB’s native analytics capabilities and rich query language. Using some clever tools we were able to make this happen in under an hour – the first time around.

将多个系统,API和第三方服务捆绑在一起可能非常困难。 最近,当我们想将数据从Segment导入MongoDB时,我们内部遇到了这个确切的问题,因此我们可以利用MongoDB的本机分析功能和丰富的查询语言。 使用一些巧妙的工具,我们能够在不到一个小时的时间内实现这一目标-这是第一次。

While this post is detailed, the actual implementation should only take around 20 minutes. I’ll start off by introducing our cast of characters (what tools we used to do this) and then we will walk through how we went about it.

虽然这篇文章很详细,但是实际的实现只需要20分钟左右。 首先,我将介绍角色转换(我们曾经使用过哪些工具),然后逐步介绍如何进行操作。

那些角色 ( The Characters )

To collect data from a variety of sources including mobile, web, cloud apps, and servers, developers have been turning to Segment since 2011. Segment consolidates all the events generated by multiple data sources into a single clickstream. You can then route the data to over 200+ integrations all at the click of a button. Companies like DigitalOcean, New Relic, InVision, and Instacart all rely on Segment for different parts of their growth strategies.

为了从移动,Web,云应用和服务器等各种来源收集数据,开发人员从2011年开始转向细分 。细分将由多个数据源生成的所有事件合并为一个点击流。 然后,您只需单击一个按钮,就可以将数据路由到200多个集成中。 像DigitalOceanNew RelicInVisionInstacart这样的公司都依靠Segment来实现其增长战略的不同部分。

To store the data generated by Segment, we turn to MongoDB Atlas – MongoDB’s database as a service. Atlas offers the best of MongoDB:

为了存储由Segment生成的数据,我们转向MongoDB Atlas – MongoDB的数据库即服务。 Atlas提供了最好的MongoDB:

  • A straightforward query language that makes it easy to work with your data

    一种直接的查询语言,可轻松处理数据
  • Native replication and sharding to ensure data can live where it needs to

    本机复制和分片以确保数据可以存放在需要的地方
  • A flexible data model that allows you to easily ingest data from a variety of sources without needing to know precisely how the data will be structured (its shape)

    灵活的数据模型,可让您轻松地从各种来源提取数据,而无需精确了解数据的结构(形状)

All this is wrapped up in a fully managed service, engineered and run by the same team that builds the database, which means that as a developer you actually can have your cake and eat it too.

所有这些都封装在一个完全托管的服务中,该服务由与构建数据库的团队一起设计和运行,这意味着作为开发人员,您实际上也可以吃蛋糕。

The final character is MongoDB Stitch, MongoDB’s serverless platform. Stitch streamlines application development and deployment with simple, secure access to data and services – getting your apps to market faster while reducing operational costs. Stitch allows us to implement server-side logic that connects third-party tools like Segment, with MongoDB, while ensuring everything from security to performance is optimized.

最后一个角色是MongoDB的无服务器平台MongoDB Stitch 。 Stitch通过对数据和服务的简单,安全的访问简化了应用程序的开发和部署–在降低运营成本的同时,将您的应用程序更快地推向市场。 Stitch允许我们实施服务器端逻辑,以将MongoDB等第三方工具与MongoDB连接起来,同时确保从安全到性能的所有方面都得到优化。

操作顺序 ( Order of Operations )

We are going to go through the following steps. If you have completed any of these already, feel free to just cherry pick the relevant items you need assistance with:

我们将执行以下步骤。 如果您已经完成其中任何一项,请随意选择需要帮助的相关项目:

  1. Setting up a Segment workspace

    设置细分工作区
  2. Adding Segment’s JavaScript library to your frontend application – I’ve also built a ridiculously simple HTML page that you can use for testing

    将SegmentJavaScript库添加到您的前端应用程序中- 我还构建了一个非常简单HTML页面,您可以将其用于测试
  3. Sending an event to Segment when a user clicks a button

    用户单击按钮时将事件发送到细分
  4. Signing up for MongoDB Atlas

    注册MongoDB Atlas
  5. Creating a cluster, so your data has somewhere to live

    创建集群,以便您的数据有生存空间
  6. Creating a MongoDB Stitch app that accepts data from Segment and saves it to your MongoDB Atlas cluster

    创建一个MongoDB Stitch应用程序以接受来自Segment的数据并将其保存到您的MongoDB Atlas集群
Join the community slack and ask questions if you are trying to follow along with a different service. 加入社区的闲散 ,如果您想跟随其他服务一起提问,请提问。

Each time Segment sees new data a webhook fires an HTTP Post request to Stitch. A Stitch function then handles the authentication of the request and, without performing any data manipulation, saves the body of the request directly to the database – ready for further analysis.

每当细分受众群看到新数据时,网络挂钩都会向Stitch发送HTTP Post请求。 然后,Stitch函数将处理请求的身份验证,并且无需执行任何数据操作即可将请求的主体直接保存到数据库中,以备进一步分析。

在细分中设置工作区 ( Setting up a Workspace in Segment )

Head over to Segment.com and sign up for an account. Once complete, Segment will automatically create a Workspace for you. Workspaces allow you to collaborate with team members, control permissions, and share data sources across your whole team. Click through to the Workspace that you've just created.

前往Segment.com并注册一个帐户。 完成后,Segment将自动为您创建一个工作区。 工作区使您可以与团队成员进行协作,控制权限并在整个团队中共享数据源。 单击进入刚刚创建的工作区。

To start collecting data in your Workspace, we need to add a source. In this case, I’m going to collect data from a website, so I’ll select that option, and on the next screen, Segment will have added a JavaScript source to my workspace. Any data that comes from our website will be attributed to this source. There is a blue toggle link I can click within the source that will give me the code I need to add to my website so it can send data to Segment. Take note of this as we will need it shortly.

要开始在您的工作区中收集数据,我们需要添加一个源。 在这种情况下,我将从网站上收集数据,因此我将选择该选项,然后在下一个屏幕上,Segment将向我的工作区添加一个JavaScript源。 来自我们网站的任何数据都将归因于此来源。 我可以在源中单击一个蓝色切换链接,该链接将为我提供我需要添加到我的网站中的代码,以便它可以将数据发送到细分。 注意这一点,因为我们很快将需要它。

向您的网站添加细分 ( Adding Segment to your Website )

I mentioned a simple sample page I had created in case you want to test this implementation outside of other code you had been working on. You can grab it from this GitHub repo.

我提到了一个我创建的简单示例页面,以防您想在自己正在研究的其他代码之外测试此实现。 您可以从此GitHub存储库中获取它。

In my sample page, you’ll see I’ve copied and pasted the Segment code and dropped it in between my page’s tags. You’ll need to do the equivalent with whatever code or language you are working in.

在示例页面中,您会看到我已经复制并粘贴了细分代码,并将其放在页面的 标签。 您需要使用任何正在使用的代码或语言进行等效处理。

If you open that page in a browser, it should automatically start sending data to Segment. The easiest way to see this is by opening Segment in another window and clicking through to the debugger.

如果您在浏览器中打开该页面,它将自动开始将数据发送到细分。 最简单的方法是在另一个窗口中打开细分,然后单击调试器。

Clicking on the debugger button in the Segment UI takes you to a live stream of events sent by your application.

单击细分用户界面中的调试器按钮,您将进入由应用程序发送的实时事件流。

自定义发送给细分的事件 ( Customizing the events you send to Segment )

The Segment library enables you to get as granular as you like with the data you send from your application.

使用细分库,您可以从应用程序发送的数据中获得所需的粒度。

As your application grows, you’ll likely want to expand the scope of what you track. Best practice requires you to put some thought into how you name events and what data you send. Otherwise different developers will name events differently and will send them at different times – read this post for more on the topic.

随着应用程序的增长,您可能希望扩大跟踪范围。 最佳实践要求您考虑如何命名事件以及发送什么数据。 否则,不同的开发人员将以不同的方式命名事件,并在不同的时间发送事件-请阅读此帖子,以获取有关该主题的更多信息。

To get us started, I’m going to assume that we want to track every time someone clicks a favorite button on a web page. We are going to use some simple JavaScript to call Segment’s analytics tracking code and send an event called a “track” to the Segment API. That way, each time someone clicks our favorite button, we'll know about it.

为了使我们入门,我假设每个人单击网页上的收藏夹按钮时,我们都要进行跟踪。 我们将使用一些简单JavaScript来调用Segment的分析跟踪代码,并将一个称为“ track”的事件发送到Segment API。 这样,每当有人单击我们喜欢的按钮时,我们都会知道。

You’ll see at the bottom of my web page, that there is a jQuery function attached to the .btn class. Let’s add the following after the alert() function.

您将在我的网页底部看到, .btn类附加了一个jQuery函数。 让我们在alert()函数之后添加以下内容。

analytics.track("Favorited", {
  itemId: this.id,
  itemName: itemName
});

Now, refresh the page in your browser and click on one of the favorite buttons. You should see an alert box come up. If you head over to your debugger window in Segment, you’ll observe the track event streaming in as well. Pretty cool, right!

现在,在浏览器中刷新页面,然后单击“收藏夹”按钮之一。 您应该会看到一个警告框。 如果转到Segment中的调试器窗口,您还将观察到跟踪事件流。 太酷了,对!

You probably noticed that the analytics code above is storing the data you want to send in a JSON document. You can add fields with more specific information anytime you like. Traditionally, this data would get sent to some sort of tabular data store, like MySQL or PostgreSQL, but then each time new information was added you would have to perform a migration to add a new column to your table. On top of that, you would likely have to update the object-relational mapping code that's responsible for saving the event in your database. MongoDB is a flexible data store, that means there are no migrations or translations needed, as we will store the data in the exact form you send it in.

您可能已经注意到,上面的分析代码正在将要发送的数据存储在JSON文档中。 您可以随时添加包含更多特定信息的字段。 传统上,此数据将发送到某种表格式数据存储区,例如MySQL或PostgreSQL,但是每次添加新信息时,您都必须执行迁移以向表中添加新列。 最重要的是,您可能必须更新负责将事件保存在数据库中的对象关系映射代码。 MongoDB是一个灵活的数据存储,这意味着不需要迁移或翻译,因为我们将以您发送数据时所用的确切格式存储数据。

MongoDB Atlas和Stitch入门 ( Getting Started with MongoDB Atlas and Stitch )

As mentioned, we’ll be using two different services from MongoDB. The first, MongoDB Atlas, is a database as a service. It’s where all the data generated by Segment will live, long-term. The second, MongoDB Stitch, is going to play the part of our backend. We are going to use Stitch to set up an endpoint where Segment can send data, once received, Stitch validates that the request Stitch was sent from Segment, and then coordinate all the logic to save this data into MongoDB Atlas for later analysis and other activities.

如前所述,我们将使用MongoDB的两种不同服务。 第一个是MongoDB Atlas,是数据库即服务。 这是Segment生成的所有数据长期存在的地方。 第二个是MongoDB Stitch,它将扮演我们后端的角色。 我们将使用Stitch设置一个端点,Segment可以在该端点上发送数据,一旦收到,Stitch便会验证Stitch的请求是从Segment发送的,然后协调所有逻辑以将该数据保存到MongoDB Atlas中,以便以后进行分析和其他活动。

第一次使用MongoDB Atlas? ( First Time Using MongoDB Atlas? )

Click here to set up an account in MongoDB Atlas.

单击此处在MongoDB Atlas中设置帐户。

Once you’ve created an account, we are going to use Atlas’s Cluster Builder to set up our first cluster (every MongoDB Atlas deployment is made up of multiple nodes that help with high availability, that’s why we call it a cluster). For this demonstration, we can get away with an M0 instance – it's free forever and great for sandboxing. It's not on dedicated infrastructure, so for any production workloads, its worth investigating other instance sizes.

创建帐户后,我们将使用Atlas的Cluster Builder来设置我们的第一个集群(每个MongoDB Atlas部署都是由多个有助于高可用性的节点组成的,这就是我们称之为集群的原因)。 在此演示中,我们可以使用M0实例-它是永久免费的,非常适合沙箱测试。 它不在专用的基础架构上,因此对于任何生产工作负载,值得研究其他实例大小。

When the Cluster Builder appears on screen, the default cloud provider is AWS, and the selected region is North Virginia. Leave these as is. Scroll down and click on the Cluster Tier section, and this will expand to show our different sizing options. Select M0 at the top of the list.

当“群集生成器”出现在屏幕上时,默认的云提供程序为AWS,所选区域为北弗吉尼亚。 保留这些。 向下滚动并单击“群集层”部分,它将展开以显示我们不同的大小选择。 选择列表顶部的M0。

You can also customize your cluster’s name, by clicking on the Cluster Name section.

您还可以通过单击“群集名称”部分来自定义群集的名称。

Once complete, click Create Cluster. It takes anywhere from 7-10 minutes to set up your cluster so maybe go grab a drink, stretch your legs and come back… When you’re ready, read on.

完成后,单击“创建群集”。 建立集群需要7至10分钟的时间,因此也许可以去喝一杯,伸展双腿然后回来……准备好之后,继续阅读。

创建针迹应用程序 ( Creating a Stitch Application )

While the Cluster is building, on the left-hand menu, click Stitch Apps. You will be taken to the stitch applications page, from where you can click Create New Application.

构建群集时,在左侧菜单上,单击Stitch Apps。 您将被带到针迹应用程序页面,从中可以单击创建新应用程序。

Give your application a name, in this case, I call it “SegmentIntegration” and link it to the correct cluster. Click Create.

为您的应用程序命名,在这种情况下,我将其命名为“ SegmentIntegration”,并将其链接到正确的集群。 单击创建。

Once the application is ready, you’ll be taken to the Stitch welcome page. In this case, we can leave anonymous authentication off.

准备好应用程序后,将转到“ Stitch”欢迎页面。 在这种情况下,我们可以取消匿名身份验证。

We do need to enable access to a MongoDB collection to store our data from Segment. For the database name I use “segment”, and for the collection, I use “events”. Click Add Collection.

我们确实需要启用对MongoDB集合的访问以存储来自Segment的数据。 对于数据库名称,我使用“段”,对于集合,我使用“事件”。 单击添加收藏集。

Next, we will need to add a service. In this case, we will be manually configuring an HTTP service that can communicate over the web with Segment’s service. Scroll down and click Add Service.

接下来,我们将需要添加服务。 在这种情况下,我们将手动配置一个HTTP服务,该服务可以通过网络与Segment的服务进行通信。 向下滚动并单击添加服务。

You’ll jump one page and should see a big sign saying, “This application has no services”… not for long. Click Add a Service… again.

您将跳到一页,并且应该看到一个大标志,上面写着:“此应用程序没有服务”……不久。 再次单击添加服务…。

From the options now visible, select HTTP and then give the service a name. I’ll use “SegmentHTTP”. Click Add Service.

从现在可见的选项中,选择HTTP,然后为服务命名。 我将使用“ SegmentHTTP”。 单击添加服务。

Next, we need to add an Incoming Webhook. A Webhook is an HTTP endpoint that will continuously listen for incoming calls from Segment, and when called, it will trigger a function in Stitch to run.

接下来,我们需要添加一个传入Webhook。 Webhook是一个HTTP端点,它将连续侦听来自Segment的传入呼叫,并在被调用时将触发Stitch中的一个函数运行。

Click Add Incoming Webhook

单击添加传入Webhook

  • Leave the default name as is and change the following fields:

    保留默认名称,并更改以下字段:
  • Turn on Respond with Result as this will return the result of our insert operation

    启用“以结果响应”,因为这将返回我们插入操作的结果
  • Change Request Validation to “Require Secret as Query Param”

    将请求验证更改为“需要秘密作为查询参数”
  • Add a secret code to the last field on the page. Important Note: We will refer to this as our “public secret” as it is NOT protected from the outside world, it’s more of a simple validation that Stitch can use before running the Function we will create. Shortly, we will also define a “private secret” that will not be visible outside of Stitch and Segment.

    将密码添加到页面的最后一个字段。 重要说明:我们将其称为“公共秘密”,因为它不受外界的保护,而更多的是Stitch在运行我们将要创建的功能之前可以使用的简单验证。 很快,我们还将定义一个在“针迹和片段”之外不可见的“私人秘密”。

Finally, click “Save”.

最后,点击“保存”。

使用缝合功能定义请求处理逻辑 ( Define Request Handling Logic with Functions in Stitch )

We define custom behavior in Stitch using functions, simple JavaScript (ES6) that can be used to implement logic and work with all the different services integrated with Stitch.

我们使用功能 ,简单JavaScript(ES6)在Stitch中定义自定义行为,该功能可用于实现逻辑并与与Stitch集成的所有不同服务一起使用。

Thankfully, we don’t need to do too much work here. Stitch already has the basics set up for us. We need to define logic that does the following things:

值得庆幸的是,我们在这里不需要做太多的工作。 Stitch已经为我们建立了基础。 我们需要定义执行以下操作的逻辑:

  1. Grabs the request signature from HTTP headers

    从HTTP标头中获取请求签名
  2. Uses the signature to validate the requests authenticity (i.e., it came from Segment)

    使用签名来验证请求的真实性(即,它来自细分)
  3. Write the request to our segment.events collection in MongoDB Atlas

    将请求写入MongoDB Atlas中的segment.events集合

Add the following to line 8, after the curly close brace }.

在大括号}之后,将以下内容添加到第8行。

const signature = payload.headers['X-Signature'];

And then use Stitch’s built-in Crypto library to generate a digest that we will compare with the signature.

然后使用Stitch的内置Crypto库生成摘要,将其与签名进行比较。

const digest = utils.crypto.hmac(payload.body.text(), context.values.get("segment_shared_secret"), "sha1", "hex");

A lot is happening here so I’ll step through each part and explain. Segment signs requests with a signature that is a combination of the HTTP body and a shared secret. We can attempt to generate an identical signature using the utils.crytop.hmac function if we know the body of the request, the shared secret, the hash function Segment uses to create its signatures, and the output format. If we can replicate what is contained within the X-Signature header from Segment, we will consider this to be an authenticated request.

这里发生了很多事情,所以我将逐步介绍每个部分并进行解释。 段使用HTTP正文和共享机密的组合对请求进行签名。 如果我们知道请求的主体,共享机密,Segment用于创建其签名的哈希函数以及输出格式,则可以尝试使用utils.crytop.hmac函数生成相同的签名。 如果我们可以从Segment复制X-Signature标头中包含的内容,则将其视为已验证请求。

*Note: This will be using a private secret, not the public secret we defined in the Settings page when we created the webhook. This secret should never be publicly visible. Stitch allows us to define values that we can use for storing variables like API keys and secrets. We will do this shortly. *

*注意:这将使用私人机密,而不是我们在创建Webhook时在“设置”页面中定义的公共机密。 这个秘密永远不应该公开显示。 Stitch允许我们定义可用于存储变量(例如API密钥和机密)的值。 我们很快会这样做。 *

验证请求是否真实并写入MongoDB Atlas ( Validating that the Request is Authentic and Writing to MongoDB Atlas )

To validate the request, we simply need to compare the digest and the signature. If they’re equivalent, then we will write to the database. Add the following code directly after we generate the digest.

要验证请求,我们只需要比较digestsignature 。 如果它们相等,那么我们将写入数据库。 生成digest后,直接添加以下代码。

if (digest == signature) {
  // Request is valid
} else {
  // Request is invalid
  console.log("Request is invalid");
}

Finally, we will augment the if statement with the appropriate behavior needed to save our data. On the first line of the if statement, we will get our “mongodb-atlas” service. Add the following code:

最后,我们将使用保存数据所需的适当行为来扩充if语句。 在if语句的第一行,我们将获得“ mongodb-atlas”服务。 添加以下代码:

let mongodb = context.services.get("mongodb-atlas");

Next, we will get our database collection so that we can write data to it.

接下来,我们将获取数据库集合,以便可以向其中写入数据。

let events = mongodb.db("segment").collection("events");

And finally, we write the data.

最后,我们写入数据。

events.insertOne(body);

Click the Save button on the top left-hand side of the code editor. At the end of this, our entire function should look something like this:

单击代码编辑器左上方的保存按钮。 最后,我们的整个函数应如下所示:

exports = function(payload) {

  var queryArg = payload.query.arg || '';
  var body = {};

  if (payload.body) {
    body = JSON.parse(payload.body.text());
  }

  // Get x-signature header and create digest for comparison
  const signature = payload.headers['X-Signature'];
  const digest = utils.crypto.hmac(payload.body.text(), 
    context.values.get("segment_shared_secret"), "sha1", "hex");

  //Only write the data if the digest matches Segment's x-signature!
  if (digest == signature) {

    let mongodb = context.services.get("mongodb-atlas");

    // Set the collection up to write data
    let events = mongodb.db("segment").collection("events");

    // Write the data
    events.insertOne(body);

  } else  {
    console.log("Digest didn't match");
  }

  return queryArg + ' ' + body.msg;
};

为MongoDB Atlas集合定义规则 ( Defining Rules for a MongoDB Atlas Collection )

Next, we will need to update our rules that allow Stitch to write to our database collection. To do this, in the left-hand menu, click on “mongodb-atlas”.

接下来,我们将需要更新允许Stitch写入数据库集合的规则。 为此,请在左侧菜单中单击“ mongodb-atlas”。

Select the collection we created earlier, called “segment.events”. This will display the Field Rules for our Top-Level Document. We can use these rules to define what conditions must exist for our Stitch function to be able to Read or Write to the collection.

选择我们之前创建的集合,称为“ segment.events ”。 这将显示我们的顶级文档的字段规则。 我们可以使用这些规则来定义Stitch函数必须具备哪些条件才能读取或写入集合。

We will leave the read rules as is for now, as we will not be reading directly from our Stitch application. We will, however, change the write rule to "evaluate" so our function can write to the database.

由于我们不会直接从Stitch应用程序中进行读取,因此我们现在将保留读取规则。 但是,我们会将写入规则更改为“求值”,以便我们的函数可以写入数据库。

Change the contents of the “Write” box:

更改“写入”框的内容:

  • Specify an empty JSON document {} as the write rule at the document level.

    在文档级别指定一个空的JSON文档{}作为写入规则。
  • Set Allow All Other Fields to Enabled, if it is not already set.

    如果尚未设置,则将“允许所有其他字段”设置为“已启用”。

Click Save at the top of the editor.

单击编辑器顶部的保存。

在MongoDB Stitch中添加秘密值 ( Adding a Secret Value in MongoDB Stitch )

As is common practice, API keys and passwords are stored as variables, meaning they are never committed to a code repo – visibility is reduced. Stitch allows us to create private variables (values) that may be accessed only by incoming webhooks, rules, and named functions.

按照惯例,API密钥和密码存储为变量,这意味着它们永远不会提交给代码存储库-降低了可见性。 Stitch允许我们创建私有变量(值),只有传入的Web钩子,规则和命名函数才能访问它们。

We do this by clicking Values on the Stitch menu, clicking Create New Value, and giving our value a name – in this case segment_shared_secret (we will refer to this as our private secret). We enter the contents in the large text box. Make sure to click Save once you’re done.

为此,请单击“针迹”菜单上的“值”,再单击“创建新值”,然后给我们的值命名(在本例中为segment_shared_secret (我们将其称为私人机密))。 我们在大文本框中输入内容。 完成后,请确保单击“保存”。

获取我们的Webhook URL ( Getting Our Webhook URL )

To copy the webhook URL across to Segment from Stitch, navigate using the Control menu: Services > SegmentHTTP > webhook0 > Settings (at the top of the page). Now copy the “Webhook URL”.

要将Webhook URL从Stitch复制到细分,请使用“控制”菜单导航:“服务”>“ SegmentHTTP”>“ webhook0”>“设置”(在页面顶部)。 现在复制“ Webhook URL”。

In our case, the Webhooks looks something like this:

在我们的例子中,Webhooks看起来像这样:

https://webhooks.mongodb-stitch.com/api/client/v2.0/app/segmentintegration/service/SegmentHTTP/incoming_webhook/webhook0

将Webhook URL添加到细分 ( Adding the Webhook URL to Segment )

Head over to Segment and log in to your workspace. In destinations, we are going to click Add Destination.

转到细分并登录到您的工作区。 在目的地中,我们将单击“添加目的地”。

Search for Webhook in the destinations catalog and click Webhooks. Once through to the next page, click Configure Webhooks. Then select any sources from which you want to send data. Once selected, click Confirm Source.

在目的地目录中搜索Webhook,然后单击Webhooks。 进入下一页后,单击“配置Webhooks”。 然后选择要从中发送数据的任何来源。 选择后,单击“确认来源”。

Next, we will find ourselves on the destination settings page. We will need to configure our connection settings. Click the box that says Webhooks (max 5).

接下来,我们将在目标设置页面上找到自己。 我们将需要配置我们的连接设置。 单击显示Webhooks(最多5个)的框。

Copy your webhook URL from Stitch, and make sure you append your public secret to the end of it using the following syntax:

从Stitch复制Webhook URL,并确保使用以下语法在其末尾附加您的公共机密:

Initial URL:

初始网址:

https://webhooks.mongodb-stitch.com/api/client/v2.0/app/segmentintegration/service/SegmentHTTP/incoming_webhook/webhook0

Add the following to the end: ?secret=

将以下内容添加到末尾: ?secret=

Final URL:

最终到达网址:

https://webhooks.mongodb-stitch.com/api/client/v2.0/app/segmentintegration/service/SegmentHTTP/incoming_webhook/webhook0?secret=PUBLIC_SECRET

Click Save

点击保存

We also need to tell Segment what our private secret is so it can create a signature that we can verify within Stitch. Do this by clicking on the Shared Secret field and entering the same value you used for the segment_shared_secret. Click Save.

我们还需要告诉Segment我们的秘密是什么,以便它可以创建一个可以在Stitch中验证的签名。 通过单击Shared Secret字段并输入与segment_shared_secret相同的值来执行此操作。 单击保存。

Finally, all we need to do is activate the webhook by clicking the switch at the top of the Destination Settings page:

最后,我们需要做的就是通过单击“目标设置”页面顶部的开关来激活Webhook:

生成事件,并在MongoDB中查看数据 ( Generate Events, and See Your Data in MongoDB )

Now, all we need to do is use our test HTML page to generate a few events that get sent to Segment – we can use Segment’s debugger to ensure they are coming in. Once we see them flowing, they will also be going across to MongoDB Stitch, which will be writing the events to MongoDB Atlas.

现在,我们需要做的就是使用我们的测试HTML页面生成一些事件,这些事件将发送到Segment –我们可以使用Segment的调试器来确保它们进入。一旦我们看到它们正在流动,它们也将遍历MongoDB。 Stitch,它将把事件写入MongoDB Atlas。

We’ll take a quick look using Compass to ensure our data is visible. Once we connect to our cluster, we should see a database called “segment”. Click on segment and then you’ll see our collection called “events”. If you click into this you’ll see a sample of the data generated by our frontend!

我们将使用Compass快速查看以确保我们的数据可见。 连接到集群后,应该会看到一个名为“ segment”的数据库。 点击细分,然后您将看到我们的集合“事件”。 如果单击此按钮,您将看到我们的前端生成的数据样本!

结束 ( The End )

Thanks for reading through – hopefully you found this helpful. If you’re building new things with MongoDB Stitch we’d love to hear about it. Join the community slack and ask questions in the #stitch channel!

感谢您的阅读-希望您发现这对您有所帮助。 如果您正在使用MongoDB Stitch构建新事物,我们很乐意听到有关它的信息。 加入社区 ,在#stitch频道中提问!

翻译自: https://scotch.io/tutorials/how-to-integrate-mongodb-atlas-and-segment-using-mongodb-stitch

mongodb atlas

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值