Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
mongoose-to-csv
Advanced tools
MongooseToCsv is a mongoose plugin that creates a CsvBuilder
instance for your Schema.
var UserSchema = new mongoose.Schema({
fullname: {type: String},
email: {type: String},
age: {type: Number},
username: {type: String}
});
UserSchema.plugin(mongooseToCsv, {
headers: 'Firstname Lastname Username Email Age',
constraints: {
'Username': 'username',
'Email': 'email',
'Age': 'age'
},
virtuals: {
'Firstname': function(doc) {
return doc.fullname.split(' ')[0];
},
'Lastname': function(doc) {
return doc.fullname.split(' ')[1];
}
}
});
var User = mongoose.model('Users', UserSchema);
// Query and stream
User.findAndStreamCsv({age: {$lt: 40}})
.pipe(fs.createWriteStream('users_under_40.csv'));
// Create stream from query results
User.find({}).exec()
.then(function(docs) {
User.csvReadStream(docs)
.pipe(fs.createWriteStream('users.csv'));
});
// Transform mongoose streams
User.find({})
.where('age').gt(20).lt(30)
.limit(10)
.sort('age')
.stream()
.pipe(User.csvTransformStream())
.pipe(fs.createWriteStream('users.csv'));
$ npm install mongoose-to-csv
Running tests requires a local mongodb server, and mocha. While most likely not a namespace issue, the test script will create a database __mongoose_to_csv_test__
, and drop the database when finished. You have been warned.
$ npm test
The options
argument is passed to the CsvBuilder
instance, please refer to
the Docs for more in-depth details. The only aditional property that can be included is the virutals
property.
The virtuals
have nothing to do with mongoose virtuals.
Creates a csv formated read stream from query results.
Transforms mongoose querystreams to csv formated streams.
Schema.find(query).stream().pipe(Schema.csvTransformStream())
FAQs
Export mongoose querys as csv streams.
The npm package mongoose-to-csv receives a total of 631 weekly downloads. As such, mongoose-to-csv popularity was classified as not popular.
We found that mongoose-to-csv demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.