Pages tagged "Mongodb"

2021

MongoDB Cheat Sheet

As frequent-but-not-every-day-one-needs-these-command MongoDB users, we, obviously, can use a cheat sheet. Here is the start of one.

List all (primary) attributes

Since not all documents may have all keys, the following method loops over all documents and collects the encountered keys.

var dbks = {};
db.___your-collection-name___.find().forEach(function(doc){Object.keys(doc).forEach(function(key){allKeys[key]=1})})
dbks;

2021-02-03: more ...