Database insertion

Estimated time: 20–30 minutes

This tutorial shows you how to subscribe to tweet data and store the tweets in a Firebase database.

[info] What you will need

Create Firebase database

In this tutorial, you will use the Twitter data from the Merging Streams tutorial and store it in a Firebase database.

  1. Visit the Firebase site in a new tab.
  2. Click Get Started.
  3. If you are not already signed in, sign in with your Google account.
  4. Click + Add Project.
  5. Name the project nio-firebase.
  6. Click Create Project.
  7. In the menu on the left, click Authentication.
  8. Click Set Up Sign-In Method.
  9. Click Email/Password.
  10. Click the Enable toggle to enable sign in with email and password.
  11. Click Save.
  12. Click the Users tab at the top.
  13. Click Add User.
  14. Create a user Email and Password, which will be used to configure the FirebaseInsert block.

[info] Why Firebase?

nio is compatible with any database regardless of format. In this tutorial, Google's Firebase is the database of choice because it stores, syncs, and distributes data in real time and it is easy to visualize in the browser.

Create service

This service will insert tweets referencing the winning company into a Firebase database.

  1. Open the nio System Designer tab.
  2. Start the tweets-count and tweets-count-winner services, if they are not already started.
  3. Click create new service.
  4. In the service name box, enter tweets-into-firebase.

Add and configure blocks

In this service, a Subscriber block is going to be configured with the same Topic as the Publisher in the tweets-count-winner service. Then, an AttributeSelector block will format the signal to match how you want it to look in the database collection. Finally, a FirebaseInsert block will store the incoming signal in your database.

The Firebase block group

The installation of the FirebaseInsert block may take a little while. All three Firebase blocks (Insert, Read, and Stream) are part of one Firebase repository. When you install the FirebaseInsert block, the other two Firebase blocks will also be downloaded to your nio instance.

  1. Drag a Subscriber block onto your canvas.
  2. Configure the block as follows:
    1. Name: Subscribe Tweets Winner
    2. Topic: workshop.tweets-count.winner
  3. Click accept.
  4. Drag an AttributeSelector block onto your canvas.
  5. Configure the block as follows:
    1. Name: Format Tweet For Database
    2. Click the + Incoming signal attributes twice and enter the following values:
      • Incoming signal attributes box 1: text
      • Incoming signal attributes box 2: created_at
      • Selector Mode: WHITELIST
  6. Click accept.

You need to add your Firebase database information into a block so nio can send the tweet messages to your database.

  1. Visit the Firebase Console.
  2. Click the nio-firebase project that you created in earlier in this tutorial.
  3. In the menu on the left, click Authentication.
  4. Click Web Setup in the upper right hand corner.
    • Note the apiKey, databaseURL, and projectId.
  5. Open the System Designer tab.
  6. Select your Tutorials instance, and click the edit button.
  7. Add your Firebase credentials to the list of environment variables
      value: <test password>
      value: <apiKey>
  8. Drag a FirebaseInsert block onto your canvas.
  9. Configure the block as follows:
    1. Name: Add Tweets To Firebase
    2. Authenticated User Email: <test email>
    3. Authenticated User Password: [[FIREBASE_PASSWORD]]
    4. API Key: [[FIREBASE_API_KEY]]
    5. Database URL: <databaseURL>
    6. Firebase Project ID: <projectId>
    7. Database Collection: /en/
    8. Exclude Existing?: True (select radio button)
  10. Click accept.

Connect blocks and start service

The tweets streaming from the Subscriber blocks will be formatted and sent to the Firebase database you created earlier.

  1. Connect the blocks as configured in the diagram.
  2. Click save.
  3. Click start.
  4. Visit the Firebase Console.
  5. Click the nio-firebase project.
  6. In the menu on the left, click Database. You should see a /en/ collection that updates every time a new tweet comes in from the Twitter Streaming API. An example is shown below.

[warning] Database not populating

If you are not seeing anything populating your Firebase database, make sure both of the tweets-count and tweets-count-winner services from the Streaming API and the Merging Streams tutorials are running.


You have learned how to insert data into a Firebase database using nio. These same principles apply to any database you may want to use.

Extra credit

Here are some ideas to improve or expand the services you just created.

  • How would you send the tweets of the trending company to a different database, such as Mongo?

Getting help

We're always happy to help with any questions you might have about the nio Platform. View the troubleshooting guide, search the documentation, or post your questions in the forum. You can also contact live support by clicking the chat icon in the lower-right corner of the nio System Designer.

Troubleshooting tips related specifically to this tutorial are presented below.

Error Possible Cause Solution
Not getting any messages in Logger Panel and no error messages. Services are not started. Make sure all services from both the Twitter and Firebase tutorials are running.

proceed to tutorial 6: database modification »

results matching ""

    No results matching ""