Skip to content

Commit

Permalink
Support for mongodb 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
bbonnin committed Aug 24, 2016
1 parent 03dbd7f commit 0faf38c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
14 changes: 7 additions & 7 deletions src/main/resources/shell_extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,30 @@ function printTable(dbquery, fields, flattenArray) {
// Flatten all the documents and get all the fields to build a table with all fields
var docs = [];
var createFieldSet = fields == null || fields.length == 0;
var fieldSet = new Set(fields);
var fieldSet = fields ? [].concat(fields) : []; //new Set(fields);

while (iterator.hasNext()) {
var doc = iterator.next();
doc = flattenObject(doc, flattenArray);
docs.push(doc);
if (createFieldSet) {
for (var i in doc) {
if (doc.hasOwnProperty(i)) {
fieldSet.add(i);
if (doc.hasOwnProperty(i) && fieldSet.indexOf(i) === -1) {
fieldSet.push(i);
}
}
}
}

fields = [...fieldSet];
fields = fieldSet;

var header = "%table ";
fields.forEach(field => header += field + "\t")
fields.forEach(function (field) { header += field + "\t" })
print(header.substring(0, header.length - 1));

docs.forEach(doc => {
docs.forEach(function (doc) {
var row = "";
fields.forEach(field => row += doc[field] + "\t")
fields.forEach(function (field) { row += doc[field] + "\t" })
print(row.substring(0, row.length - 1));
});
}
Expand Down

0 comments on commit 0faf38c

Please sign in to comment.