Explore Developer Center's New Chatbot! MongoDB AI Chatbot can be accessed at the top of your navigation to answer all your MongoDB questions.

MongoDB Developer
MongoDB
plus
Sign in to follow topics
MongoDB Developer Centerchevron-right
Developer Topicschevron-right
Productschevron-right
MongoDBchevron-right

Using AWS Rekognition to Analyse and Tag Uploaded Images

Aydrian Howard1 min read • Published Jan 28, 2022 • Updated Sep 11, 2024
AWSMongoDBJavaScript
Facebook Icontwitter iconlinkedin icon
Rate this article
star-empty
star-empty
star-empty
star-empty
star-empty
Some features mentioned below will be deprecated on Sep. 30, 2025. Learn more.
Please note: This article discusses Stitch. Stitch is now MongoDB Realm. All the same features and functionality, now with a new name. Learn more here. We will be updating this article in due course.
Computers can now look at a video or image and know what's going on and, sometimes, who's in it. Amazon Web Service Rekognition gives your applications the eyes it needs to label visual content. In the following, you can see how to use Rekognition along with MongoDB Stitch to supplement new content with information as it is inserted into the database.
You can easily detect labels or faces in images or videos in your MongoDB application using the built-in AWS service. Just add the AWS service and use the Stitch client to execute the AWS SES request right from your React.js application or create a Stitch function and Trigger. In a recent Stitchcraft live coding session on my Twitch channel, I wanted to tag an image using label detection. I set up a trigger that executed a function after an image was uploaded to my S3 bucket and its metadata was inserted into a collection.
1exports = function(changeEvent) {
2 const aws = context.services.get('AWS');
3 const mongodb = context.services.get("mongodb-atlas");
4 const insertedPic = changeEvent.fullDocument;
5
6 const args = {
7 Image: {
8 S3Object: {
9 Bucket: insertedPic.s3.bucket,
10 Name: insertedPic.s3.key
11 }
12 },
13 MaxLabels: 10,
14 MinConfidence: 75.0
15 };
16
17 return aws.rekognition()
18 .DetectLabels(args)
19 .then(result => {
20 return mongodb
21 .db('data')
22 .collection('picstream')
23 .updateOne({_id: insertedPic._id}, {$set: {tags: result.Labels}});
24 });
25};
With just a couple of service calls, I was able to take an image, stored in S3, analyse it with Rekognition, and add the tags to its document. Want to see how it all came together? Watch the recording on YouTube with the Github repo in the description. Follow me on Twitch to join me and ask questions live.
✅ Already have an AWS account? Atlas supports paying for usage via the AWS Marketplace (AWS MP) without any upfront commitment — simply
sign up for MongoDB Atlas via AWS Marketplace.

Facebook Icontwitter iconlinkedin icon
Rate this article
star-empty
star-empty
star-empty
star-empty
star-empty
Related
Podcast

Hardware Sizing for MongoDB With Jay Runkel


Sep 11, 2024 | 26 min
Article

Building Remix Applications with the MongoDB Stack


Apr 02, 2024 | 4 min read
Quickstart

5 Different Ways to Deploy a Free Database with MongoDB Atlas


Feb 03, 2023 | 5 min read
Tutorial

Using MongoDB Atlas Triggers to Summarize Airbnb Reviews with OpenAI


Oct 31, 2023 | 4 min read