Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mongo ConnectAsync undefined #76

Open
DeanKamali opened this issue Dec 16, 2018 · 0 comments
Open

mongo ConnectAsync undefined #76

DeanKamali opened this issue Dec 16, 2018 · 0 comments

Comments

@DeanKamali
Copy link

Hi

It seems that ConnectAsync has been depreciated, and I'm unable to run the following example.

var db = mongo.ConnectAsync('mongodb://localhost:27017/testdb');
var collection = db.then(function(db) {
  return db.collection('testcollection');
});

etl.file('test.csv')
  .pipe(etl.csv())
  .pipe(etl.collect(10))
  .pipe(etl.mongo.insert(collection));

I have tried using newer newer syntax, but getting TypeError: Cannot read property 'insert' of undefined

const fs  = require('fs')
const etl = require('etl');

const MongoClient = require("mongodb").MongoClient;

var collection;

(async() => {
    await MongoClient.connect('mongodb://127.0.0.1:3001', function (err, client) {
        if (err) throw err;

        var db = client.db('meteor');
     
        collection = db.collection("Carrier")
    }); 
})()

fs.createReadStream("ins.csv")
  // parse the csv file
  .pipe(etl.csv())
  // map `date` into a javascript date and set unique _id
  .pipe(
    etl.map(d => {
     return d
  )
  // collect 1000 records at a time for bulk-insert
  .pipe(etl.collect(10))
  .pipe(etl.mongo.insert(collection))
  .promise()
  .then(() => console.log("done"), e => console.log("error", e));

I'm seeing the following error:

node index.js
(node:97320) DeprecationWarning: current URL string parser is deprecated, and will be removed ina future version. To use the new parser, pass option { useNewUrlParser: true } to MongoClient.connect.
error TypeError: Cannot read property 'insert' of undefined
    at collection.then.collection (/Users/dck/Projects/csv-load/node_modules/etl/lib/mongo/insert.js:24:35)
    at tryCatcher (/Users/dck/Projects/csv-load/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/dck/Projects/csv-load/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/Users/dck/Projects/csv-load/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromiseCtx (/Users/dck/Projects/csv-load/node_modules/bluebird/js/release/promise.js:606:10)
    at _drainQueueStep (/Users/dck/Projects/csv-load/node_modules/bluebird/js/release/async.js:142:12)
    at _drainQueue (/Users/dck/Projects/csv-load/node_modules/bluebird/js/release/async.js:131:9)
    at Async._drainQueues (/Users/dck/Projects/csv-load/node_modules/bluebird/js/release/async.js:147:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/dck/Projects/csv-load/node_modules/bluebird/js/release/async.js:17:14)
    at processImmediate (timers.js:632:19)
Unhandled rejection TypeError: Cannot read property 'insert' of undefined
    at collection.then.collection (/Users/dck/Projects/csv-load/node_modules/etl/lib/mongo/insert.js:24:35)
    at tryCatcher (/Users/dck/Projects/csv-load/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/dck/Projects/csv-load/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/Users/dck/Projects/csv-load/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromiseCtx (/Users/dck/Projects/csv-load/node_modules/bluebird/js/release/promise.js:606:10)
    at _drainQueueStep (/Users/dck/Projects/csv-load/node_modules/bluebird/js/release/async.js:142:12)
    at _drainQueue (/Users/dck/Projects/csv-load/node_modules/bluebird/js/release/async.js:131:9)
    at Async._drainQueues (/Users/dck/Projects/csv-load/node_modules/bluebird/js/release/async.js:147:5)
    at Immediate.Async.drainQueues [as _onImmediate] (/Users/dck/Projects/csv-load/node_modules/bluebird/js/release/async.js:17:14)
    at processImmediate (timers.js:632:19)

Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant