• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mongodb-js / mongodb-mcp-server / 14590701503

22 Apr 2025 08:50AM UTC coverage: 50.118% (-0.9%) from 50.98%
14590701503

Pull #82

github

blva
lint
Pull Request #82: add create project tool

23 of 150 branches covered (15.33%)

Branch coverage included in aggregate %.

8 of 31 new or added lines in 3 files covered. (25.81%)

4 existing lines in 1 file now uncovered.

401 of 696 relevant lines covered (57.61%)

36.62 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

31.82
/src/tools/mongodb/update/updateMany.ts
1
import { z } from "zod";
6✔
2
import { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
3
import { MongoDBToolBase } from "../mongodbTool.js";
6✔
4
import { ToolArgs, OperationType } from "../../tool.js";
5

6
export class UpdateManyTool extends MongoDBToolBase {
6✔
7
    protected name = "update-many";
42✔
8
    protected description = "Updates all documents that match the specified filter for a collection";
42✔
9
    protected argsShape = {
42✔
10
        collection: z.string().describe("Collection name"),
11
        database: z.string().describe("Database name"),
12
        filter: z
13
            .object({})
14
            .passthrough()
15
            .optional()
16
            .describe(
17
                "The selection criteria for the update, matching the syntax of the filter argument of db.collection.updateOne()"
18
            ),
19
        update: z
20
            .object({})
21
            .passthrough()
22
            .optional()
23
            .describe("An update document describing the modifications to apply using update operator expressions"),
24
        upsert: z
25
            .boolean()
26
            .optional()
27
            .describe("Controls whether to insert a new document if no documents match the filter"),
28
    };
29
    protected operationType: OperationType = "update";
42✔
30

31
    protected async execute({
32
        database,
33
        collection,
34
        filter,
35
        update,
36
        upsert,
37
    }: ToolArgs<typeof this.argsShape>): Promise<CallToolResult> {
38
        const provider = await this.ensureConnected();
×
39
        const result = await provider.updateMany(database, collection, filter, update, {
×
40
            upsert,
41
        });
42

43
        let message = "";
×
44
        if (result.matchedCount === 0) {
×
45
            message = `No documents matched the filter.`;
×
46
        } else {
47
            message = `Matched ${result.matchedCount} document(s).`;
×
48
            if (result.modifiedCount > 0) {
×
49
                message += ` Modified ${result.modifiedCount} document(s).`;
×
50
            }
51
            if (result.upsertedCount > 0) {
×
52
                message += ` Upserted ${result.upsertedCount} document(s) (with id: ${result.upsertedId?.toString()}).`;
×
53
            }
54
        }
55

56
        return {
×
57
            content: [
58
                {
59
                    text: message,
60
                    type: "text",
61
                },
62
            ],
63
        };
64
    }
65
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc