This repository is deprecated and no longer actively maintained. It contains outdated code examples or practices that do not align with current MongoDB best practices. While the repository remains accessible for reference purposes, we strongly discourage its use in production environments. Users should be aware that this repository will not receive any further updates, bug fixes, or security patches. This code may expose you to security vulnerabilities, compatibility issues with current MongoDB versions, and potential performance problems. Any implementation based on this repository is at the user's own risk. For up-to-date resources, please refer to the MongoDB Developer Center.
Developer Relation Engagement & Activity Metrics
- Collect metrics from the different platforms the Developer Relations team is using to produce content for reporting & analysis purposes.
The code currently pulls analytics about videos in the MongoDB YouTube channel. For more information on the metrics we pull, see the YouTube API Docs.
The stats are displayed in a MongoDB Charts dashboard.
A daily trigger makes a call to the get_all_youtube_videos function. The function retrieves information about all videos that have been uploaded to the MongoDB YouTube channel.
A daily trigger makes a call to the get_yesterday_youtube_video_stats function. The function retrieves stats from three days prior. (YouTube only provides stats when all metrics that you request are available. Some of our metrics appear to be on a three-day delay.)
To retrieve older stats, use the get_previous_youtube_video_stats function. You can call the function by opening it in the Realm web UI and typing something like the following into the console: exports(2021, 1, 1, 15)
. Optionally, you can use generate-historical-youtube-data.js, which will call the function repeatedly for you.
While you're gathering stats, you may want to easily delete stats for a given month. You can use delete.js to do so.
If you want to sanity check that the stats you've pulled make sense, you can use test-views.js. This script checks that the sum of the daily views stored in the youtube_stats
collection aligns with the total views stat that YouTube provides (which we store in the youtube_videos
collection in statistics.viewCount
). Keep in mind that these stats may not be a perfect match because:
- We collect stats on a three-day delay and YouTube's total views stat is current
- Any views prior to when you started collecting stats will not be included in the calculated sum
The script reports how many videos were published in the given time period for each of the following categories:
- 0 views
- Calculated sum of views exactly matches what YouTube is reporting
- Calculated sum of views is close to what YouTube is reporting
- Calculated sum of views is not close to what YouTube is reporting
For videos with views that are not close to what YouTube is reporting, the script displays output you can you manually review to determine if the stats are close enough or if there is an error in the view count.
This section contains random tips and tricks we don't want to forget.
To move data from Dev to Staging:
mongodump --uri mongodb+srv://username:password@uri-for-dev/dream
mongorestore --uri mongodb+srv://username:password@uri-for-staging --drop
The steps to configure authentication on first deployment are a little fiddly. They are as follows:
realm-cli import --project-id YOUR-PROJECT-ID
- This will fail. That's expected!
- Go to the GCP Credentials dashboard https://console.cloud.google.com/apis/credentials
- Create a new OAuth client ID; Web application. Add the URL for the 'google_oauth > oauth' webhook as an Authorized Redirect URL
- Add the credentials as Realm secrets:
GOOGLE_CLIENT_ID
andGOOGLE_CLIENT_SECRET
- Configure Slack notifications
- Create a new application in the Slack API dashboard and configure a new Incoming Webhook. The webhook should be connected to a channel where you want the Slack notifications to be posted.
- Copy the Webhook URL.
- In the Realm UI, create a new secret named
SLACK_CHANNEL_NOTIFICATIONS
that has the value of the Webhook URL you copied in the previous step.
realm-cli import
- this should now succeed.- Now, in the browser, go to the URL for the
google_oauth > oauth
webhook.- Authorize the app to access the MongoDB account. You may have to click through some scary dialogs.
- When you see a json response saying
{ 'message': 'ok' }
then you've successfully authorized the app. - This should create a document in the
auth.auth_tokens
collection, containing both anaccess_token
and arefresh_token
. If not, something's gone wrong.
- Go to the "OAuth Consent Screen" in the YouTube dashboard, and ensure the app is configured as "External", under "Testing" and that your MongoDB email account is added to the test users list.
- You're done!
If you need to clear your OAuth token, see the instructions in this pull request.
Ask in the MongoDB Developer Community.