Giter Site home page Giter Site logo

gulp-mongodb-data's Introduction

gulp-mongodb-data

Load JSON files and mongoexport dumps into MongoDB with Gulp

Information

Packagegulp-mongodb-data
Description Load JSON files and mongoexport dumps into MongoDB with Gulp (gulpjs.com)
Tested Node Versions 6.3.0, 5.12.0, 4.4.7, 0.12.15, 0.10.46 (on Debian Linux)
Gulp Version 3.x

Usage

Install

$ npm install gulp-mongodb-data --save-dev

Example

var gulp = require('gulp')
var mongodbData = require('gulp-mongodb-data')

// Load JSON files, with arrays of objects, or data dumps from mongoexport,
// into the specified MongoDB server, using file names as collection names
gulp.task('metadata', function() {
  gulp.src('./db/metadata/*.json')
    .pipe(mongodbData({ mongoUrl: 'mongodb://localhost/mydb' }))
})

// Load JSON files, with arrays of objects, or data dumps from mongoexport,
// into the specified MongoDB server, using file names as collection names,
// and retain the _id data type (useful for when using strings or numbers as
// _id)
gulp.task('metadata', function() {
  gulp.src('./db/metadata/*.json')
    .pipe(mongodbData({
      mongoUrl: 'mongodb://localhost/mydb',
      idAsObjectID: false
    }))
})

// Load JSON file, with array of objects, or data dumps from mongoexport,
// into the specified MongoDB server, using the specified collection name
gulp.task('metadata', function() {
  gulp.src('./db/metadata/users-test.json')
    .pipe(mongodbData({
      mongoUrl: 'mongodb://localhost/mydb',
      collectionName: 'users'
    }))
})

// Load JSON file, with array of objects, or data dumps from mongoexport,
// into the specified MongoDB server, using the specified collection name,
// and dropping the collection before bulk inserting data
gulp.task('metadata', function() {
  gulp.src('./db/metadata/users-test.json')
    .pipe(mongodbData({
      mongoUrl: 'mongodb://localhost/mydb',
      collectionName: 'users',
      dropCollection: true
    }))
})

JSON files

JSON files should be formatted as an array of valid JSON objects for the plugin to be able to process it. You can even include a specific Object ID.

[{
  "a": 1
},
{
  "_id": "578611d17c8a27dd5b329fd5",
  "a": 2
},
...]

The _id field is usually converted to an ObjectID before inserting, if _id is a string. By setting the idAsObjectID option to false, you can use any supported data type as _id (except arrays).

[{
  "_id": "697d1942-47bc-4fc5-ac92-6e8b1dbb649f",
  "a": 1
},
{
  "_id": 13.37,
  "a": 2
},
{
  "_id": true,
  "a": 3
},
...]

JSON files containing data dumps from mongoexport can also be used.

{"_id":{"$oid":"5787d450596cca272cab90ba"},"first":"Brian","last":"Flanagan","birthdate":{"$date":"1962-07-03T00:00:00.000Z"},"appearance":1,"male":true}
{"_id":{"$oid":"5787d450596cca272cab90bb"},"first":"Doug","last":"Coughlin","birthdate":{"$date":"1947-06-23T00:00:00.000Z"},"appearance":2,"male":true}
{"_id":{"$oid":"5787d450596cca272cab90bc"},"first":"Jordan","last":"Mooney","birthdate":{"$date":"1963-10-06T00:00:00.000Z"},"appearance":3,"male":false}

License

(MIT License)

Copyright (c) 2016 Benne [email protected]

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

gulp-mongodb-data's People

Contributors

benne avatar denneulin avatar

Watchers

James Cloos avatar Max avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.