How to access the results of mongodb find() operation using mongodb javascript native driver

I have a database in mongodb and I'm connecting to it through NodeJS and mongodb native driver. I'm trying to write a javascript code to print in the browser the information retrieved from the database through db.foo.find() operation.

I am currently able to print the value part of the json data. However, i need to print the key part as well.

Example : json data { key1:v1, key2:v2 ....} i need a way to access the key1 and key2 values through javascript code without knowing them prehand??

You can use the for...in syntax to iterate over the keys of an object.

Object.keys(json).forEach(function (key) {
    console.log(key);
});