Skip to content

Commit 68fcc6e

Browse files
committed
Release 0.2.4
1 parent c934d78 commit 68fcc6e

File tree

2 files changed

+47
-32
lines changed

2 files changed

+47
-32
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mongodb-shell-extensions",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "Useful MongoDB shell extensions",
55
"files": [
66
"src",

released/mongorc.js

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10244,7 +10244,7 @@ moment.fn.within = function(range) {
1024410244

1024510245
/* global chatty */
1024610246

10247-
chatty('\033[1;32m+ MongoDB Shell Extensions (0.2.3) by Gabriele Lana <gabriele.lana@gmail.com>\033[0m')
10247+
chatty('\033[1;32m+ MongoDB Shell Extensions (0.2.4) by Gabriele Lana <gabriele.lana@gmail.com>\033[0m')
1024810248

1024910249
DBCollection.prototype.last = function(n) {
1025010250
return this.find().sort({_id: -1}).limit(n || 1)
@@ -10303,38 +10303,53 @@ var printcsv = function(x) {
1030310303
})
1030410304
}
1030510305

10306-
var tocsv = function(x) {
10307-
var lines = [],
10308-
fieldNames = {},
10309-
encodedDocuments = x.map(function(doc) {
10310-
return _.reduce(doc, function(values, value, field) {
10311-
fieldNames[field] = true
10312-
values[field] = tojson(value).replace(
10313-
/^(?:ISODate|ObjectId)\((.*)\)$/,
10314-
function(_, contentAsString) {
10315-
return contentAsString
10316-
}
10317-
)
10318-
return values
10319-
}, {})
10320-
})
10321-
10322-
fieldNames = _.keys(fieldNames)
10306+
var tocsv = (function() {
10307+
var flatten = function(o) {
10308+
return _.reduce(o, function(flattened, value, field) {
10309+
if (_.isPlainObject(value)) {
10310+
_.forEach(flatten(value), function(nestedValue, nestedField) {
10311+
flattened[[field, nestedField].join('.')] = nestedValue
10312+
})
10313+
} else {
10314+
flattened[field] = value
10315+
}
10316+
return flattened
10317+
}, {})
10318+
}
1032310319

10324-
lines.push(fieldNames.join(','))
10325-
encodedDocuments.forEach(function(encodedDocument) {
10326-
lines.push(
10327-
fieldNames.map(function(fieldName) {
10328-
if (encodedDocument[fieldName] !== undefined) {
10329-
return encodedDocument[fieldName]
10330-
}
10331-
return '""'
10332-
}).join(',')
10333-
)
10334-
})
10320+
return function(x) {
10321+
var lines = [],
10322+
fieldNames = {},
10323+
encodedDocuments = x.map(function(doc) {
10324+
return _.reduce(flatten(doc), function(values, value, field) {
10325+
fieldNames[field] = true
10326+
values[field] = tojson(value).replace(
10327+
/^(?:ISODate|ObjectId)\((.*)\)$/,
10328+
function(_, contentAsString) {
10329+
return contentAsString
10330+
}
10331+
)
10332+
return values
10333+
}, {})
10334+
})
10335+
10336+
fieldNames = _.keys(fieldNames)
10337+
10338+
lines.push(fieldNames.join(','))
10339+
encodedDocuments.forEach(function(encodedDocument) {
10340+
lines.push(
10341+
fieldNames.map(function(fieldName) {
10342+
if (encodedDocument[fieldName] !== undefined) {
10343+
return encodedDocument[fieldName]
10344+
}
10345+
return ''
10346+
}).join(',')
10347+
)
10348+
})
1033510349

10336-
return new CSV(lines)
10337-
}
10350+
return new CSV(lines)
10351+
}
10352+
})()
1033810353

1033910354
DBQuery.prototype.reverse = function() {
1034010355
if (!this._query.query || _.isEmpty(this._query.query)) {

0 commit comments

Comments
 (0)