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

Introducing MongoDB 8.0, the fastest MongoDB ever!
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 Amazon Q Developer generative AI–powered coding assistant

Shane McAllister3 min read • Published Sep 25, 2024 • Updated Sep 25, 2024
AWSAIMongoDBJavaScriptJavaPython
Facebook Icontwitter iconlinkedin icon
Rate this tutorial
star-empty
star-empty
star-empty
star-empty
star-empty
In 2023, MongoDB collaborated with the Amazon CodeWhisperer team to fine tune the Foundational Models to deliver top-notch code suggestions — trained on, and tailored for, MongoDB. Now, we've taken this collaboration even further with Amazon Q Developer, the latest evolution of Amazon’s AI-powered coding assistant, to provide even better intelligent code completions and enhanced productivity for your MongoDB-based projects.
Amazon Q Developer enhances the coding experience, providing faster and more context-aware code completions, which seamlessly integrate with MongoDB operations. Its AI capabilities have been expanded, offering better support for complex tasks and workflows and with features like Q Chat, you can even start a conversation with Amazon Q to explore and explain code suggestions further. Check out this short video for an idea of the capabilities of Amazon Q with MongoDB.
This tutorial below will help you get Amazon Q Developer up and running in VS Code, but Q is also available for a number of other IDEs, including including JetBrains (as in the video above), IntelliJ IDEA, Visual Studio as well as the CLI and the AWS Console. On the Amazon Q Site, you can find tutorials that demonstrate how to set up Amazon Q on different IDEs, as well as other documentation.
Installing Amazon Q for VS Code
Amazon Q 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 Amazon Q and it will show up in the extension marketplace. AmazonQ extension
  3. Once found, hit Install. Amazonq details
  4. Once installed, you’ll be prompted to authorize Amazon Q via a Builder ID to connect to your AWS developer account (or set up a new account if you don’t already have one). enter image description here
Using Amazon Q
The are 2 ways you can interact with Amazon Q - Inline Code Suggestions or Q Chat
Inline code suggestions
amazon q running
With Amazon Q Developer installed and running, as you enter your prompt or code, Q will offer inline code suggestions. If you want to keep the suggestion, use TAB to accept it. Q 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 Q 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 Q something to work with. The more code your file contains, the more context Q 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
Using Q Chat
If you prefer a Chat like interface, Q Chat is here to help also and you can interact in a more conversation way, and all the while, being able to insert code suggestions back into your project. The choice is yours, inline or chat, you'll get same capability and assistance, all underpinned by MongoDB training and fine tuning.
amazon q chat
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 Q in your MongoDB development, we’d love to hear from you, so please visit our Forums to let us know how you're getting on with it, and how it's helping in your workflow.
We can’t wait to see your thoughts and impressions of MongoDB and Amazon Q together.
Top Comments in Forums
There are no comments on this article yet.
Start the Conversation

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

Real-Time Chat in a Phaser Game with MongoDB and Socket.io


Feb 03, 2023 | 11 min read
Quickstart

An Introduction to GDELT Data


May 24, 2022 | 5 min read
Tutorial

Getting Started With MongoDB and AWS CodeWhisperer


Sep 26, 2024 | 3 min read
Quickstart

Creating, Reading, Updating, and Deleting MongoDB Documents With PHP


Sep 11, 2024 | 8 min read