Print or Printjson no longer products trees or tables

Erico Georgiades shared this question 2 years ago
Answered

I used to use variables to store data, loop to add more fields and then export my documents into a csv, all with the power of javascript and the print or printjson commands.

Now, the output is only the raw log, and it never interprets my data, thus cannot visualize it or export it.

Please help.

Replies (1)

photo
1

I don't quite understand your needs. Can you elaborate on it? it's best to give illustrations or other referable solutions.

photo
1

For example, this used to work, but no longer does. I recently upgraded to the latest version.

var users = db.users.find().sort({ _id: -1 }).limit(10);

users.forEach(user => {
    printjson(user);
});
Either I use `print` or `printjson` neither render the table view, and neither allow me to export the results.

photo
1

The "print" data is not displayed in tree/table view, it is the equivalent of console.log.
If you want to display the results in tree/table view, simply change the script to the following

db.users.find().sort({ _id: -1 }).limit(10);
photo
1

My script cannot be interpreted that easily. I often use such code that loops and changes data or does much more. The example I gave is indeed simple enough to interpret differently.

It's disappointing that most of your competitors still have this feature, and so did you, prior to the update.

Version 5.x works the way that I mentioned, however, it does not connect to my newer databases, thus I was forced to upgrade and pay for the latest version, which was a step back for me, mostly due to this change.

photo
2

Version 5.0 does not have this feature either. If you need to export a variable (array or cursor), you can put the value on the last line of the script.

e.g. //put the value that you want to export on the last line of the script

let users = db.users.find().sort({ _id: -1 }).limit(10);
users=users.toArray().map(it=>{
    //do something
})
users; //just put "users" in the last line to show it in tree/table view



photo
Leave a Comment
 
Attach a file