
Security News
PodRocket Podcast: Inside the Recent npm Supply Chain Attacks
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
mongo-graph
Advanced tools
Visualizes connections between documents in a mongo database.
npm install mongo-graph -g
You also need GraphViz. On a Mac with homebrew you can brew install graphviz
.
mongo test-db --quiet --eval 'db.foo.remove(); db.foo.insert([
{
"_id" : ObjectId("000000000000000000000001"),
"other_foo" : ObjectId("000000000000000000000002")
},
{
"_id" : ObjectId("000000000000000000000002"),
"other_foo" : ObjectId("000000000000000000000001")
}])'
mongoexport --db test-db --collection foo | mongo-graph | dot -Tpng -o out.png && open out.png
Data in a db often has links between documents in different collections. The output of mongoexport
contains no data about the associated collection. However, mongo-graph can interpret a __collection
field as metadata about which collection the json object belongs to. You can do this at the db level, or use a handy command-line json modifier like jsontool:
mongo test-db --quiet --eval 'db.foo.remove(); db.foo.insert([
{
"_id" : ObjectId("000000000000000000000001"),
"bar" : ObjectId("000000000000000000000003")
},
{
"_id" : ObjectId("000000000000000000000002"),
"bar" : ObjectId("000000000000000000000004")
}])'
mongo test-db --quiet --eval 'db.bar.remove(); db.bar.insert([
{
"_id" : ObjectId("000000000000000000000003"),
},
{
"_id" : ObjectId("000000000000000000000004"),
}])'
mongoexport --jsonArray --db test-db --collection foo | json -e 'this.__collection="foo"' > foo.in
mongoexport --jsonArray --db test-db --collection bar | json -e 'this.__collection="bar"' > bar.in
cat foo.in bar.in | mongo-graph | dot -Tpng -o out.png && open out.png
Labeling nodes by ObjectId is not very useful. You can override this default by attaching a __label
field to your json objects:
mongo test-db --quiet --eval 'db.foo.remove(); db.foo.insert([
{
"_id" : ObjectId("000000000000000000000001"),
"bar" : ObjectId("000000000000000000000003"),
"human_readable": "1"
},
{
"_id" : ObjectId("000000000000000000000002"),
"bar" : ObjectId("000000000000000000000004"),
"human_readable": "2"
}])'
mongo test-db --quiet --eval 'db.bar.remove(); db.bar.insert([
{
"_id" : ObjectId("000000000000000000000003"),
"human_readable": "3"
},
{
"_id" : ObjectId("000000000000000000000004"),
"human_readable": "4"
}])'
mongoexport --jsonArray --db test-db --collection foo | json -e 'this.__collection="foo"; this.__label=this.human_readable' > foo.in
mongoexport --jsonArray --db test-db --collection bar | json -e 'this.__collection="bar"; this.__label=this.human_readable' > bar.in
cat foo.in bar.in | mongo-graph | dot -Tpng -o out.png && open out.png
FAQs
visualize mongo data
We found that mongo-graph demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket CEO Feross Aboukhadijeh discusses the recent npm supply chain attacks on PodRocket, covering novel attack vectors and how developers can protect themselves.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.