ANNOUNCEMENTVoyage AI joins MongoDB to power more accurate and trustworthy AI applications on Atlas. Learn more >Voyage AI joins MongoDB to power more accurate and trustworthy AI applications on Atlas. >>
NEWMongoDB 8.0: Experience unmatched speed and performance. Check it out >MongoDB 8.0: Experience unmatched speed and performance. >>
AnnouncementMongoDB 8.0: Experience unmatched speed and performance. Check it out >MongoDB 8.0: Experience unmatched speed and performance. >>

Getting Started With MongoDB and AWS CodeWhisperer

MongoDB

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.

Step 1. Open VS Code and navigate to the extensions store (bottom icon on the left panel).

Step 2. Search for AWS CodeWhisperer, and it will show up as part of the AWS Toolkit.

Screen grab showing searching for the AWS CodeWhisperer in the extensions store.

Step 3. Once found, hit Install. Next, you’ll see the full AWS Toolkit Listing.

Screen grab of the store function for hitting install.

Step 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).

Screen grab of the page for authorizing Amazon CodeWhisperer.

Using AWS CodeWhisperer

Navigating code suggestions

Screen grab of the developer tools drop down window for Amazon CodeWhisperer

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 the 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.
// Take a JSON document as a String and store it in MongoDB returning the _id

Or

//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.
// This Java class works with MongoDB sync driver.
// 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.