kisonay
kisonay

Reputation: 361

PouchDB Load producing error

I'm trying to use PouchDB to load initial content into my database using the following code snippet:

db2.load('bloggr.txt').then(function() {
    // done loading!
}).catch(function(err) {
    // HTTP error or something like that
    console.log(err);
});

I'm using some of the example content provided by PouchDB Load. the database gets created, and records are created but I get a Javascript error in the console.

TypeError: Cannot read property 'db_name' of undefined
at pouchdb.load.js:56

looking at line 56 I see the following

var target = new db.constructor(info.db_name,

Anyone have any idea what would cause this?

Upvotes: 0

Views: 419

Answers (1)

Colin Skow
Colin Skow

Reputation: 1006

This is working perfect for me:

<!DOCTYPE html>
<html>
<head>
  <title>PouchDB-Load Test</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/pouchdb/4.0.3/pouchdb.js"></script>
  <script src="https://rawgit.com/nolanlawson/pouchdb-load/master/dist/pouchdb.load.js"></script>
</head>
<body>
  <script type="text/javascript">
    var db2 = new PouchDB('http://localhost:5984/pouchdb-load-test/');
    console.log('Starting load');
    db2.load('bloggr.txt')
    .then(function() {
      console.log('Success!');
    })
    .catch(function(err) {
      // HTTP error or something like that
      console.log(err);
    });
  </script>
</body>
</html>

Make sure you have CORS enabled in your CouchDB config. It will fail with file:// so needs to be run from a web server.

Upvotes: 1

Related Questions