本页显示的示例附带自然语言提示和AI客户端返回的结果。这些示例展示了如何使用MongoDB MCP Server 与Atlas 集群中的示例数据进行交互。
您可以在AI客户端中输入提示。AI客户端执行提示中请求的任务并返回结果。返回的输出取决于您使用的AI客户端和大语言模型。
为了安全起见, Atlas组织和项目标识符、密码和其他隐私信息在此页面的示例输出中显示为 XXX
。当您运行类似的提示时,输出将包含完整信息。
先决条件
注意
MCP 服务器配置文件示例包括 --readOnly
,以确保对数据进行只读访问权限。通常,启用只读模式以防止数据更改。
要启用写入操作,请省略 --readOnly
或将操作系统环境变量 MDB_MCP_READ_ONLY
设立为 false
。有关更多信息,请参阅启用 MCP 服务器只读模式。
MCP 服务器配置文件示例将 type
字段设立为 "stdio"
。
type
可以设立为以下之一:
"stdio"
,它使用标准输入和输出与 MCP 服务器进行通信。stdio
适用于大多数AI客户端。通常使用stdio
。"http"
,这将启用与 MCP 服务器的HTTP通信。然后,您可以使用HTTP从 Web客户端与 MCP 服务器交互。警告
在未实现身份验证和安全性的情况下,不建议将HTTP用于生产用途。
MCP 服务器配置文件示例还将 MCP 服务器名称设立为 "MongoDB"
。启动 MCP 服务器后,您可以更改服务器名称以匹配 MCP 服务器的名称。服务器名称向AI客户端标识 MCP 服务器。
示例
以下部分显示了可以在AI客户端中运行的示例提示。
显示Atlas组织和项目
以下示例显示了Atlas组织和项目。输出显示从AI客户端返回的结果以及客户端用于执行请求的工具的名称(atlas-list-orgs
和 atlas-list-projects
)。
Show my Atlas organizations and projects
Ran ``atlas-list-orgs`` Ran ``atlas-list-projects`` Here are your MongoDB Atlas organizations and projects: Organizations: TestOrganization Organization ID: XXX Projects: TestProject Project ID: XXX Organization: TestOrganization Created: August 7, 2020 at 11:48:55 AM You have one organization containing one project. This project contains your TestCluster that we're currently connected to.
显示Atlas数据库
以下示例返回可用于当前集群连接的数据库列表。
Show my Atlas databases
Ran ``list-databases`` Here are the databases in your Atlas cluster "TestCluster": Sample Databases: sample_mflix - 138.4 MB (Movie database with films, theaters, users, comments) sample_training - 53.6 MB (Training data for learning MongoDB) sample_airbnb - 55.3 MB (Airbnb listings and reviews data) sample_analytics - 10.0 MB (Analytics and customer data) sample_restaurants - 6.8 MB (Restaurant and review data) sample_weatherdata - 2.7 MB (Weather observation data) sample_geospatial - 1.3 MB (Geospatial data examples) sample_supplies - 1.1 MB (Supply chain data) sample_guides - 41 KB (Getting started guides) System Databases: local - 4.1 GB (MongoDB internal database) admin - 365 KB (Administrative database) Your cluster contains MongoDB's sample datasets, which are great for learning and testing. The largest databases are sample_mflix (movies), sample_training, and sample_airbnb. Would you like me to explore any specific database or show you the collections within one of them?
显示Atlas sample_mflix 数据库中的集合
以下示例返回Atlas sample_mflix
数据库中的集合列表。
Show the collections in the Atlas sample_mflix database
Ran ``list-collections`` Here are the collections in the sample_mflix database: Core Collections: movies - Main collection containing movie data (titles, genres, cast, ratings, etc.) users - User profiles and account information comments - User comments and reviews on movies theaters - Movie theater locations and details sessions - User session data Additional Collections: embedded_movies - Movies collection with embedded/denormalized data structure The movies collection contains detailed information about films including plot, cast, directors, ratings, release dates, and genres. The comments collection links to movies and users to store user reviews and discussions. Would you like me to explore any specific collection in more detail, such as showing sample documents or collection statistics?
总结Atlas电影合集
以下示例按惊悚片类型汇总了电影集合。AI客户端分析电影集合并返回惊悚片和统计数据的摘要。
Summarize the Atlas movies collection by thrillers
I'll help you analyze the Atlas movies collection focusing on thrillers. First, let me check what databases are available in your connected cluster. Ran ``list-databases`` Perfect! I can see you have the sample_mflix database which contains the movies collection. Let me check the collections in that database: Ran ``list-collections`` Great! Now let me analyze the movies collection to find thrillers and provide a summary. First, let me check the schema to understand how genres are stored: Ran ``collection-schema`` Perfect! I can see that genres are stored as an array of strings. Now let me get a count of thriller movies and then perform an aggregation to summarize them: Ran ``count`` Now let me create a comprehensive summary of thriller movies using aggregation: Ran ``aggregate`` I see there are some data quality issues. Let me get better data by filtering for movies with numeric ratings: Ran ``aggregate`` Now let me get some more summary statistics by decade: Ran ``aggregate`` Here's a comprehensive analysis of thriller movies in your Atlas sample_mflix collection: Overall Statistics Total Thriller Movies: 2,454 films Time Span: 1924 to 2011 Average Rating: 6.3/10 (IMDb) Average Runtime: 105 minutes Total IMDb Votes: 85.8 million across all thrillers Top-Rated Thriller Movies Drishyam (2013) - 8.9/10 - Indian thriller directed by Jeethu Joseph Tinker Tailor Soldier Spy (1979) - 8.7/10 - British spy thriller Rear Window (1954) - 8.6/10 - Alfred Hitchcock classic The Silence of the Lambs (1991) - 8.6/10 - Psychological thriller Se7en (1995) - 8.6/10 - David Fincher crime thriller The Usual Suspects (1995) - 8.6/10 - Neo-noir mystery Léon: The Professional (1994) - 8.6/10 - Action thriller Psycho (1960) - 8.6/10 - Another Hitchcock masterpiece Memento (2000) - 8.5/10 - Christopher Nolan psychological thriller Trends by Decade 1920s-1950s: Few thrillers but high quality (avg 7.2-7.8 rating) 1960s-1970s: Growing popularity, still maintaining quality 1980s: Significant growth (200 films), quality decline begins 1990s: Peak production era (417 films), avg 6.3 rating 2000s: Highest volume (854 films), avg 6.24 rating 2010s: 730 films, lowest average rating (6.12) The data shows that while thriller production increased dramatically from the 1980s onward, the average quality (as measured by IMDb ratings) has generally declined, suggesting the genre became more commercialized with higher volume but potentially lower artistic standards in recent decades.
复制电影集合
以下示例复制 movies
集合。
Make a copy of the movies collection named movies_copy
I'll create a copy of the movies collection named movies_copy. I'll use an aggregation pipeline with $out to copy all documents from the movies collection to a new movies_copy collection. Ran ``aggregate`` Perfect! I've successfully created a copy of the movies collection named movies_copy. Let me verify the copy was created correctly by checking the document count: Ran ``count`` Found 21349 documents in the collection "movies_copy" Excellent! The movies_copy collection has been successfully created with all 21,349 documents from the original movies collection. The copy operation completed successfully and you now have an identical backup of your movies collection.
将文档添加到新电影集合
以下示例将文档添加到 movies_copy
集合中。
Add a document to the movies_copy collection
I'll add a new document to the movies_copy collection. Let me create a sample movie document with the same structure as the existing movies: Ran ``insert-many`` Perfect! I've successfully added a new movie document to the movies_copy collection. Here's what I added: New Movie Added: Title: "The AI Thriller" Genres: Thriller, Sci-Fi, Drama Year: 2024 Runtime: 118 minutes IMDb Rating: 7.8/10 (125,000 votes) Cast: John Smith, Sarah Johnson, Michael Chen Director: Alex Rodriguez Rating: PG-13 The document was inserted with ID: 684b15fb5084ddef1f265e8f Let me verify the collection now has one additional document: Ran ``count`` Confirmed! The movies_copy collection now contains 21,350 documents (up from 21,349), including your new thriller movie about AI consciousness.
创建集合以存储购买的电影
以下示例创建了一个新集合来存储购买的电影。
Create a new collection to store movie purchases data that includes geospatial and timeseries fields
I'll create a new collection for storing movie purchases data with geospatial and timeseries fields. Let me first create the collection and then add some sample documents with the appropriate structure. Ran ``create-collection`` Now I'll insert sample documents that include geospatial data (customer location, theater location) and timeseries data (purchase timestamp, viewing timestamp): Ran ``insert-many`` Perfect! I've created the movie_purchases collection with sample data that includes both geospatial and timeseries fields. Here's what the collection contains: Collection Structure Geospatial Fields: customer_location: GeoJSON Point with customer's coordinates theater_location: GeoJSON Point with theater coordinates customer_address: Human-readable address information Timeseries Fields: purchase_timestamp: When the purchase was made viewing_timestamp: When the movie was actually watched viewing_duration_minutes: How long the customer watched completion_percentage: Percentage of movie completed Sample Data Added: Purchase 1: Customer in San Francisco bought "The Shawshank Redemption" rental for $12.99 Purchase 2: Customer in New York purchased "Pulp Fiction" for $15.99 Purchase 3: Customer in Los Angeles rented "Se7en" for $9.99 Now let me create a geospatial index to optimize location-based queries: Ran ``create-index`` Excellent! The movie_purchases collection is now ready with: Geospatial capabilities - 2dsphere index for location-based queries Timeseries optimization - Index on purchase timestamps Sample data - 3 purchase records across different US cities This collection can now support queries like: Finding purchases within a certain radius of a location Analyzing purchase patterns over time Correlating viewing behavior with geographic regions Time-based analytics and trending
创建新的Atlas项目和免费集群
以下示例创建了一个新的Atlas项目,并在新项目中创建了一个免费集群。
Create a new Atlas project named myNewProject and create a free cluster named myNewCluster in the new project, add access list for my current IP, create a database user named myNewUser with read and write access to the new cluster, and return the connection string for the new cluster
I'll create a new Atlas project, free cluster, and set up all the necessary access details for you. Ran ``atlas-create-project`` Great! I've created a new project named "myNewProject" in your MongoDB Atlas organization. Now let's list the projects to get the project ID for the new project: Ran ``atlas-list-projects`` Now I'll create a free cluster named "myNewCluster" in the new project: Ran ``atlas-create-free-cluster`` Now, I'll add your current IP address to the access list: Ran ``atlas-create-accees-list`` Now let's create a database user named "myNewUser" with read and write access: Ran ``atlas-create-db-user`` Perfect! Everything has been set up successfully: New Project Information: Project Name: myNewProject Project ID: XXX New Cluster Information: Cluster Name: myNewCluster Region: US East (US_EAST_1) Database User: Username: myNewUser Password: XXX Access: Read and write to any database Connection String: mongodb+srv://myNewUser:XXX@myNewCluster.mongodb.net/ Your current IP address has been added to the access list, so you should be able to connect to the cluster from your current location. The cluster will take a few minutes to fully provision and be ready for connections.
将输出导出到文件
以下示例运行聚合管道并将结果导出到文件系统中的EJSON文件。
导出的结果将保存到运行 MCP 服务器的计算机上的文件中。您还可以使用AI客户端应用程序通过 exported-data
资源访问权限导出的数据。
导出文件存储在exportPath
配置选项指定的文件系统路径中。在exportTimeout
配置选项指定的时间段后,可以删除导出文件。有关更多详细信息,请参阅导出数据。
Summarize and export the contents of the movies collection.
I'll help you summarize and export the contents of the movies collection from your connected MongoDB Atlas cluster. Let's do this in two steps: 1. First, I'll create a summary of the movies collection using an aggregation pipeline. 2. Then I'll export the results using the export tool. Let's start by getting a summary of the movies collection: Ran ``aggregate`` Now that we have a summary of the movies collection, let's create a more focused dataset to export. Let's get the top 10 highest-rated movies: Ran ``aggregate`` Now, let's export this data using the MCP Server export tool: Ran ``export`` I've successfully summarized and exported the contents of the movies collection from your MongoDB Atlas cluster. Here's a breakdown of what I did: Movies Collection Summary Collection Overview: The collection contains 21,349 movie documents Time span: 1896 to 2016 (120 years of cinema history) Average IMDb rating: 6.66 out of 10 Average runtime: ~104 minutes Top Genres: Drama (12,385 movies) Comedy (6,532 movies) Romance (3,318 movies) Crime (2,457 movies) Thriller (2,454 movies) Top Directors: Woody Allen (40 movies) Martin Scorsese (32 movies) Takashi Miike (31 movies) Steven Spielberg (29 movies) John Ford (29 movies) Top Languages: English (14,639 movies) French (2,405 movies) Spanish (1,600 movies) German (1,377 movies) Italian (1,228 movies) Highest Rated Movies: Band of Brothers (2001) - 9.6/10 Planet Earth (2006) - 9.5/10 The Civil War (1990) - 9.4/10 A Brave Heart: The Lizzie Velasquez Story (2015) - 9.4/10 Cosmos (1980) - 9.3/10 Export Details The data has been exported to a JSON file in relaxed format. You can access the exported file at: /Users/XXX/.mongodb/mongodb-mcp/exports/68b8c10a6d0291128800be0b/sample_mflix.movies.68b8c2496d0291128800be0d.json The export includes: Genre summary with counts and average ratings Runtime statistics (min, max, average) Year-by-decade summary with counts and ratings Top directors with film counts Language distribution Top 10 highest-rated movies This export provides a comprehensive overview of the movies collection that can be easily shared or imported into other tools for further analysis or visualization.