setProfilingLevel

Sets the database profiling level for queries run using the SingleStore Kai (mongodb://) endpoint.

By default, query profiling is disabled for MongoDB® queries. To profile and collect resource usage metrics for MongoDB® queries, set the profiling level to either 1 or 2.

This command is an extension of the MongoDB® setProfilingLevel() command.

Syntax

db.setProfilingLevel(<profiling_level>, <options>)

Arguments

  • profiling_level: Specifies the profiling level. It can have the following values:

    • 0: (Default) Disable profiling.

    • 1: Profile queries that exceed the specified slowms threshold or match the specified filter.

    • 2: Profile all queries and operations.

  • options: Specifies additional profiling options. If an integer is specified, the slowms threshold is updated with the specified value. It can have the following values:

    Option

    Description

    Default Value

    slowms

    Specifies the threshold in milliseconds for queries to be considered slow. Queries that take longer than the specified threshold are profiled.

    100

    failed

    Enables profiling of failed queries.

    false

Remarks

  • Run the getProfilingStatus() command to view the current profiling level.

  • The profile information also contains the SQL queries run to achieve the specified MongoDB® query/operation.

Examples

Example 1

The following example enables profiling, runs a query, and returns the profile information for the query.

  1. Enable profiling.

    db.setProfilingLevel(2)
  2. Run a sample MongoDB® query. For example, the following query finds all the documents in a collection named exampleCollection where Qty is greater than 25:

    db.exampleCollection.find({Qty:{$gt: 25}})
  3. View the profile information.

    db.system.profile.find().sort({ts: -1}).limit(1)
    [ { ts: Mon Mar 03 2025 17:30:01 GMT+0530 (India Standard Time),
        ns: 'dbTest.exampleCollection',
        op: 'query',
        millis: new Long("109"),
        ok: 1,
        client: '10.0.137.81:35940',
        command: 
         { find: 'exampleCollection',
           filter: { Qty: { '$gt': 25 } },
           lsid: { id: new UUID("8ab9be41-646f-4a59-9f04-bc8370be95de") },
           '$db': 'dbTest' },
        sqlCommands: [ 'USING dbTest\nWITH\n`exampleCollection.find` AS (SELECT \'irm+QWRvSlmfBLyDcL6V3g==.D1qyPeKoaso=\' AS kai)\nSELECT BSON_EXCLUDE_MASK(_more, \'{"_id":1}\') AS _more_1, _id FROM dbTest.exampleCollection WHERE BSON_EXTRACT_BIGINT(_more, \'Qty\') > 25' ] } ]

    Note that the query profile contains information about the MongoDB® query and the equivalent SQL query. The sqlCommands section in the output shows the SQL commands run to achieve the search operation.

Additional Examples

  • To log failed queries and queries that exceed the specified slowms time:

    db.setProfilingLevel(1, {failed:true,slowms:60000})
  • To profile and log all the queries and operations:

    db.setProfilingLevel(2)
  • To disable profiling:

    db.setProfilingLevel(0)
  • To view the profiling metrics for the last 5 logged queries:

    db.system.profile.find().sort({ts: -1}).limit(5)

Last modified: March 25, 2025

Was this article helpful?

Verification instructions

Note: You must install cosign to verify the authenticity of the SingleStore file.

Use the following steps to verify the authenticity of singlestoredb-server, singlestoredb-toolbox, singlestoredb-studio, and singlestore-client SingleStore files that have been downloaded.

You may perform the following steps on any computer that can run cosign, such as the main deployment host of the cluster.

  1. (Optional) Run the following command to view the associated signature files.

    curl undefined
  2. Download the signature file from the SingleStore release server.

    • Option 1: Click the Download Signature button next to the SingleStore file.

    • Option 2: Copy and paste the following URL into the address bar of your browser and save the signature file.

    • Option 3: Run the following command to download the signature file.

      curl -O undefined
  3. After the signature file has been downloaded, run the following command to verify the authenticity of the SingleStore file.

    echo -n undefined |
    cosign verify-blob --certificate-oidc-issuer https://oidc.eks.us-east-1.amazonaws.com/id/CCDCDBA1379A5596AB5B2E46DCA385BC \
    --certificate-identity https://kubernetes.io/namespaces/freya-production/serviceaccounts/job-worker \
    --bundle undefined \
    --new-bundle-format -
    Verified OK