npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@mongosh/snippet-change-stream-monitor

v0.1.0

Published

Mongosh snippet that allows users to monitor Change Streams on the current server.

Downloads

7

Readme

change-stream-monitor

Index

This snippet allows mongosh users to monitor Change Streams on the current server.

On installation of this snippet, the following are available to the user.

listChangeStreams(extended?: boolean, allUsers?: boolean, nsFilter?: Array)

Prints a table with the currently open Change Streams. Note that the table resizes itself based on the size of the terminal.

The behaviour of the function can be controlled with the available parameters (see parameter defaults for default behaviour). See prettyPrintChangeStreamPipeline() to pretty print a change stream pipeline. See ChangeStreamsData and ExtendedChangeStreamsData for data outputted in extended and non-extended mode.

  • extended - Controls whether a simple or extended output is presented. Refer to ExtendedChangeStreamsData. Defaults to false.
  • allUsers - Boolean that correspond's to the allUsers flag of the $currentOp MongoDB Pipeline Stage i.e. If set to false, $currentOp only reports on operations/idle connections/idle cursors/idle sessions belonging to the user who ran the command. If set to true, $currentOp reports operations belonging to all users. Defailts to true.
  • nsFilter - An optional array of namespace filter. Defaults to [] i.e. to filter.

| Column Name | Extended Output | Description | |----------------|-----------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ConnID | No | An identifier for the connection where the specific operation originated. | | AppName | No | The identifier of the client application which ran the operation. Use the appName connection string option to set a custom value for the appName field. | | Remote | No | The IP address (or hostname) and the ephemeral port of the client connection where the operation originates. | | Driver | No | The MongoDB Driver used to connect and run the Change Stream. | | NS | No | The namespace the operation targets. A namespace consists of the database name and the collection name concatenated with a dot (.); that is, ".". | | Type | No | The type of operation. Values are either: op / idleSession / idleCursor. | | Pipeline | No | The Change Stream pipeline. Use prettyPrintChangeStreamPipeline(connId) to pretty print the full pipeline. | | LastAccessDate | No | The date and time when the cursor was last used. | | Docs Returned | No | The cumulative number of documents returned by the cursor. | | Active | Yes | A boolean value specifying whether the operation has started. | | User | Yes | Users associated with the operation | | CursorId | Yes | The ID of the cursor. | | CreatedDate | Yes | The date and time when the cursor was created. |

Sample Output - Normal Mode

replset [primary] test> listChangeStreams()
  ┏━━━━━━━━━━━┳━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━┓
  ┃  ConnID   ┃  AppName   ┃  Remote      ┃  Driver      ┃  NS          ┃  Type  ┃  Pipeline    ┃  LastAccess  ┃  DocsReturn  ┃
  ┃           ┃            ┃              ┃              ┃              ┃        ┃              ┃  Date        ┃  ed          ┃
  ┡━━━━━━━━━━━╇━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━┩
  │  74       │  cs2       │  127.0.0.1:  │  mongo-java  │  test.event  │  op    │  [           │  "2024-04-2  │  0           │
  │           │            │  54989       │  -driver|sy  │  s           │        │  {           │  2T13:23:10  │              │
  │           │            │              │  nc: 4.9.1   │              │        │  "$changeSt  │  .160Z"      │              │
  │           │            │              │              │              │        │  ream": {}   │              │              │
  │           │            │              │              │              │        │  },          │              │              │
  │           │            │              │              │              │        │  {           │              │              │
  │           │            │              │              │              │        │  "$match":   │              │              │
  │           │            │              │              │              │        │  {           │              │              │
  │           │            │              │              │              │        │  "operation  │              │              │
  │           │            │              │              │              │        │  Type": {    │              │              │
  │           │            │              │              │              │        │  "$in": [    │              │              │
  │           │            │              │              │              │        │  "insert",   │              │              │
  │           │            │              │              │              │        │  "update"    │              │              │
  │           │            │              │              │              │        │  ]           │              │              │
  │           │            │              │              │              │        │  }           │              │              │
  │           │            │              │              │              │        │  }           │              │              │
  │           │            │              │              │              │        │  }           │              │              │
  │           │            │              │              │              │        │  ]           │              │              │
  ├───────────┼────────────┼──────────────┼──────────────┼──────────────┼────────┼──────────────┼──────────────┼──────────────┤
  │  79       │  cs1       │  127.0.0.1:  │  mongo-java  │  test.event  │  op    │  [           │  "2024-04-2  │  0           │
  │           │            │  55011       │  -driver|sy  │  s           │        │  {           │  2T13:23:10  │              │
  │           │            │              │  nc: 4.9.1   │              │        │  "$changeSt  │  .181Z"      │              │
  │           │            │              │              │              │        │  ream": {}   │              │              │
  │           │            │              │              │              │        │  },          │              │              │
  │           │            │              │              │              │        │  {           │              │              │
  │           │            │              │              │              │        │  "$match":   │              │              │
  │           │            │              │              │              │        │  {           │              │              │
  │           │            │              │              │              │        │  "operation  │              │              │
  │           │            │              │              │              │        │  Type": {    │              │              │
  │           │            │              │              │              │        │  "$in": [    │              │              │
  │           │            │              │              │              │        │  "insert",   │              │              │
  │           │            │              │              │              │        │  "update"    │              │              │
  │           │            │              │              │              │        │  ]           │              │              │
  │           │            │              │              │              │        │  }           │              │              │
  │           │            │              │              │              │        │  }           │              │              │
  │           │            │              │              │              │        │  }           │              │              │
  │           │            │              │              │              │        │  ]           │              │              │
  └───────────┴────────────┴──────────────┴──────────────┴──────────────┴────────┴──────────────┴──────────────┴──────────────┘
Found 2 change streams

Sample Output - Extended

replset [primary] test> listChangeStreams(true)
  ┏━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┳━━━━━━━━━━┓
  ┃  ConnID  ┃  AppNam  ┃  Remote  ┃  Driver  ┃  NS      ┃  Type  ┃  Pipeli  ┃  LastAc  ┃  DocsRe  ┃  Active  ┃  User    ┃  Cursor  ┃  Create  ┃
  ┃          ┃  e       ┃          ┃          ┃          ┃        ┃  ne      ┃  cessDa  ┃  turned  ┃          ┃          ┃  Id      ┃  dDate   ┃
  ┃          ┃          ┃          ┃          ┃          ┃        ┃          ┃  te      ┃          ┃          ┃          ┃          ┃          ┃
  ┡━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━╇━━━━━━━━━━┩
  │  74      │  cs2     │  127.0.  │  mongo-  │  test.e  │  op    │  [       │  "2024-  │  0       │  true    │  john@a  │  754369  │  "2024-  │
  │          │          │  0.1:54  │  java-d  │  vents   │        │  {       │  04-22T  │          │          │  dmin    │  716098  │  04-22T  │
  │          │          │  989     │  river|  │          │        │  "$chan  │  13:24:  │          │          │          │  703700  │  12:15:  │
  │          │          │          │  sync:   │          │        │  geStre  │  25.528  │          │          │          │  0       │  31.896  │
  │          │          │          │  4.9.1   │          │        │  am":    │  Z"      │          │          │          │          │  Z"      │
  │          │          │          │          │          │        │  {}      │          │          │          │          │          │          │
  │          │          │          │          │          │        │  },      │          │          │          │          │          │          │
  │          │          │          │          │          │        │  {       │          │          │          │          │          │          │
  │          │          │          │          │          │        │  "$matc  │          │          │          │          │          │          │
  │          │          │          │          │          │        │  h": {   │          │          │          │          │          │          │
  │          │          │          │          │          │        │  "opera  │          │          │          │          │          │          │
  │          │          │          │          │          │        │  tionTy  │          │          │          │          │          │          │
  │          │          │          │          │          │        │  pe": {  │          │          │          │          │          │          │
  │          │          │          │          │          │        │  "$in":  │          │          │          │          │          │          │
  │          │          │          │          │          │        │  [       │          │          │          │          │          │          │
  │          │          │          │          │          │        │  "inser  │          │          │          │          │          │          │
  │          │          │          │          │          │        │  t",     │          │          │          │          │          │          │
  │          │          │          │          │          │        │  "updat  │          │          │          │          │          │          │
  │          │          │          │          │          │        │  e"      │          │          │          │          │          │          │
  │          │          │          │          │          │        │  ]       │          │          │          │          │          │          │
  │          │          │          │          │          │        │  }       │          │          │          │          │          │          │
  │          │          │          │          │          │        │  }       │          │          │          │          │          │          │
  │          │          │          │          │          │        │  }       │          │          │          │          │          │          │
  │          │          │          │          │          │        │  ]       │          │          │          │          │          │          │
  ├──────────┼──────────┼──────────┼──────────┼──────────┼────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┼──────────┤
  │  79      │  cs1     │  127.0.  │  mongo-  │  test.e  │  op    │  [       │  "2024-  │  0       │  true    │  mary@a  │  697267  │  "2024-  │
  │          │          │  0.1:55  │  java-d  │  vents   │        │  {       │  04-22T  │          │          │  dmin    │  149292  │  04-22T  │
  │          │          │  011     │  river|  │          │        │  "$chan  │  13:24:  │          │          │          │  716100  │  12:16:  │
  │          │          │          │  sync:   │          │        │  geStre  │  25.542  │          │          │          │  0       │  01.889  │
  │          │          │          │  4.9.1   │          │        │  am":    │  Z"      │          │          │          │          │  Z"      │
  │          │          │          │          │          │        │  {}      │          │          │          │          │          │          │
  │          │          │          │          │          │        │  },      │          │          │          │          │          │          │
  │          │          │          │          │          │        │  {       │          │          │          │          │          │          │
  │          │          │          │          │          │        │  "$matc  │          │          │          │          │          │          │
  │          │          │          │          │          │        │  h": {   │          │          │          │          │          │          │
  │          │          │          │          │          │        │  "opera  │          │          │          │          │          │          │
  │          │          │          │          │          │        │  tionTy  │          │          │          │          │          │          │
  │          │          │          │          │          │        │  pe": {  │          │          │          │          │          │          │
  │          │          │          │          │          │        │  "$in":  │          │          │          │          │          │          │
  │          │          │          │          │          │        │  [       │          │          │          │          │          │          │
  │          │          │          │          │          │        │  "inser  │          │          │          │          │          │          │
  │          │          │          │          │          │        │  t",     │          │          │          │          │          │          │
  │          │          │          │          │          │        │  "updat  │          │          │          │          │          │          │
  │          │          │          │          │          │        │  e"      │          │          │          │          │          │          │
  │          │          │          │          │          │        │  ]       │          │          │          │          │          │          │
  │          │          │          │          │          │        │  }       │          │          │          │          │          │          │
  │          │          │          │          │          │        │  }       │          │          │          │          │          │          │
  │          │          │          │          │          │        │  }       │          │          │          │          │          │          │
  │          │          │          │          │          │        │  ]       │          │          │          │          │          │          │
  └──────────┴──────────┴──────────┴──────────┴──────────┴────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┴──────────┘
Found 2 change streams

listChangeStreams.help()

Provides help on how to use the function.

prettyPrintChangeStreamPipeline(connectionId: any)

Pretty prints the Change Stream pipeline for a given Connection ID.

  • connectionId - The connection ID where the change stream is executing.

Example

replset [primary] test> prettyPrintChangeStreamPipeline(74)
[
  { '$changeStream': {} },
  {
    '$match': { operationType: { '$in': [ 'insert', 'update' ] } }
  }
]

prettyPrintChangeStreamPipeline.help()

Provides help on how to use the function.

ChangeStreamsData.help()

Describes the table output in normal mode.

ExtendedChangeStreamsData.help()

Describes the table output in extended mode.