Вопрос

I'm trying to populate my CompoundJS application's Mongo database with seed files, but whenever I run compound seed, the terminal hangs after my console.log statements... the database fills, but I have to kill the command with Ctrl-c.

I've tried doing compound seed harvest, but that doesn't create proper seed files, so I've decided to make my own. Here is my respective code:

db/seeds/development/Host.js (seed file)

console.log("Seeding Hosts....");

var hosts = [
  {
    hid: '1',
    name: 'MY API',
    domain: 'mydomain.com'
  }
];

hosts.forEach(function(obj, err){
  Host.create(obj, function(err, host){
    console.log('host Added: ', host);
  });
});

db/schema.js

var Host = describe('Host', function () {
    property('hid', String);
    property('name', String);
    property('domain', String);
    set('restPath', pathTo.hosts);
});

config/database.js

module.exports = {
    development: {
        driver:   'mongodb',
        url:      'mongodb://localhost/apicache-dev'
    },
    test: {
        driver:   'mongodb',
        url:      'mongodb://localhost/apicache-test'
    },
    production: {
        driver:   'mongodb',
        url:      'mongodb://localhost/apicache-production'
    }
};

Like I said, when I run compound seed, it shows both console.log statements, and it puts my data into the database, but it just hangs... never actually returning to the command line, so I'm forced to kill it with Ctrl-c. I would like to solve this problem, as I have to automate this process, and it's a bit hard automating if it's just hanging. What am I doing wrong? Any help would be appreciated!

Cross-posted.

EDIT

So when I try to use the Coffee script version that's generated from compound seed harvest:

db/seeds/development/Host.coffee

Host.seed ->
    hid: '1'
    name: 'MY API'
    domain: 'mydomain.com'
    id: "52571edd2ac9056339000001"

I get the error collection name must be a String. So I was a little curious and went to where that error was being generated... in node_modules/jugglingdb-mongodb/node_modules/mongodb/lib/mongodb/collection.js on line 103. I put a console.log(collectionName) right before that if statement and saw an interesting output...

{ hid: '1',
  name: 'MY API',
  domain: 'mydomain.com',
  id: NaN }

So clearly it's not a string, but a hash object, and my collection's name (Host) is nowhere in sight. Seems like a bug to me.

Это было полезно?

Решение

So I finally got it to work. Apparently, there was something wrong with the auto-genned id from the harvest command, so I ended up deleting that line, and voila! Planting the seeds works like a charm. I converted the rest of my JS files to Coffee script files and everything works. Sometimes you just need to have a conversation with yourself on the Internet...

Here's my seed file:

Host.seed ->
  hid: '1'
  name: 'MY API'
  domain: 'mydomain.com'

And doing compound seed works without hanging and populates the database. Guess Coffee script is the way to go?

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top