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

Join us at AWS re:Invent 2024! Learn how to use MongoDB for AI use cases.
MongoDB Developer
MongoDB
plus
Sign in to follow topics
MongoDB Developer Centerchevron-right
Developer Topicschevron-right
Productschevron-right
MongoDBchevron-right

Getting Started With MongoDB and AWS CodeWhisperer

Shane McAllister3 min read • Published Nov 06, 2023 • Updated Sep 26, 2024
AWSAIMongoDBJavaScriptJavaPython
Facebook Icontwitter iconlinkedin icon
Rate this tutorial
star-empty
star-empty
star-empty
star-empty
star-empty
All of the features of AWS CodeWhisperer have moved to Amazon Q Developer. You can see the updated post about how to use Amazon Q HERE
Amazon CodeWhisperer is trained on billions of lines of code and can generate code suggestions — ranging from snippets to full functions — in real-time, based on your comments and existing code. AI code assistants have revolutionized developers’ coding experience, but what sets Amazon CodeWhisperer apart is that MongoDB has collaborated with the AWS Data Science team, enhancing its capabilities!
At MongoDB, we are always looking to enhance the developer experience, and we've fine-tuned the AWS CodeWhisperer Foundational Models to deliver top-notch code suggestions — trained on, and tailored for, MongoDB. This gives developers of all levels the best possible experience when using AWS CodeWhisperer for MongoDB functions.
This tutorial will help you get AWS CodeWhisperer up and running in VS Code, but CodeWhisperer also works with a number of other IDEs, including IntelliJ IDEA, AWS Cloud9, AWS Lambda console, JupyterLab, and Amazon SageMaker Studio. On the Amazon CodeWhisperer site, you can find tutorials that demonstrate how to set up AWS CodeWhisperer on different IDEs, as well as other documentation.
Note: Amazon CodeWhisperer allows users to start without an AWS account because usually, creating an AWS account requires a credit card. Currently, CodeWhisperer is free for individual users. So it’s super easy to get up and running.
Installing Amazon CodeWhisperer for VS Code
CodeWhisperer doesn’t have its own VS Code extension. It is part of a larger extension for AWS services called AWS Toolkit. AWS Toolkit is available in the VS Code extensions store.
  1. Open VS Code and navigate to the extensions store (bottom icon on the left panel).
  2. Search for AWS CodeWhisperer and it will show up as part of the AWS Toolkit. Searching for the AWS ToolKit Extension
  3. Once found, hit Install. Next, you’ll see the full AWS Toolkit Listing The AWS Toolkit full listing
  4. Once installed, you’ll need to authorize Amazon CodeWhisperer via a Builder ID to connect to your AWS developer account (or set up a new account if you don’t already have one). Authorise AWS CodeWhisperer
Using AWS CodeWhisperer
Navigating code suggestions
AWS CodeWhisperer Running
With Amazon CodeWhisperer installed and running, as you enter your prompt or code, CodeWhisperer will offer inline code suggestions. If you want to keep the suggestion, use TAB to accept it. AWS CodeWhisperer may provide multiple suggestions to choose from depending on your use case. To navigate between suggestions, use the left and right arrow keys to view them, and TAB to accept.
If you don’t like the suggestions you see, keep typing (or hit ESC). The suggestions will disappear, and Amazon CodeWhisperer will generate new ones at a later point based on the additional context.
Requesting suggestions manually
You can request suggestions at any time. Use Option-C on Mac or ALT-C on Windows. After you receive suggestions, use TAB to accept and arrow keys to navigate.
Getting the best recommendations
For best results, follow these practices.
  • Give Amazon CodeWhisperer something to work with. The more code your file contains, the more context CodeWhisperer has for generating recommendations.
  • Write descriptive comments in natural language — for example
1// Take a JSON document as a String and store it in MongoDB returning the _id
Or
1//Insert a document in a collection with a given _id and a discountLevel
  • Specify the libraries you prefer at the start of your file by using import statements.
1// This Java class works with MongoDB sync driver.
2// This class implements Connection to MongoDB and CRUD methods.
  • Use descriptive names for variables and functions
  • Break down complex tasks into simpler tasks
Provide feedback
As with all generative AI tools, they are forever learning and forever expanding their foundational knowledge base, and MongoDB is looking for feedback. If you are using Amazon CodeWhisperer in your MongoDB development, we’d love to hear from you.
We’ve created a special “codewhisperer” tag on our Developer Forums, and if you tag any post with this, it will be visible to our Amazon CodeWhisperer project team and we will get right on it to help and provide feedback. If you want to see what others are doing with CodeWhisperer on our forums, the tag search link will jump you straight into all the action.
We can’t wait to see your thoughts and impressions of MongoDB and Amazon CodeWhisperer together.

Facebook Icontwitter iconlinkedin icon
Rate this tutorial
star-empty
star-empty
star-empty
star-empty
star-empty
Related
Article

The Top 4 Reasons Why You Should Use MongoDB


Sep 23, 2022 | 9 min read
Article

Mapping Terms and Concepts from SQL to MongoDB


Oct 01, 2024 | 15 min read
Tutorial

How to Build a Go Web App with Gin, MongoDB, and AI


Aug 30, 2024 | 11 min read
Quickstart

MongoDB and Node.js 3.3.2 Tutorial - CRUD Operations


Oct 01, 2024 | 17 min read