简体   繁体   中英

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??

您可以使用for ... in语法来迭代对象的键。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM