azat-co / mongoui

MongoDB admin UI server written in Node.js 🎮

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Collections named with "." missing full name

AndyScott77 opened this issue · comments

If you have a collections that contain "." the collection selection dropdown only renders the name upto the "." char.

For example, if I have a collections named :

  • Foo.Bar
  • Foo.Baz

The collection drop down lists :

  • Foo
  • Foo

Attached is a patch that fixes the issue.

However, here's a rundown of the changes...

I extract the name of the db into a var dbName

Where you remove the systems collections, which is where the collections which have "." char in their name issue is caused, I use a tmpName var to store the name & test against.

Then I update the name of the collection by updating el.name with the dbName + '.' removed.

Here's the actual code that the patch will generate :

store.afterDb("set", "dbName", function(txn, doc, prevDoc, done) {
  if (txn && (txn.length > 2) && txn[3][1]) {

    // get the name of the db
    var dbName = txn[3][1];

    //filter dbName based on existing list
    db = monk(config.database.default.host + ':' + config.database.default.port + '/' + txn[3][1]);
    db.driver.collectionNames(function(e, names) {
      if (e) {
        console.error(e);
        process.exit(1);
      }
      //TODO: abstract it
      names.forEach(function(el,i,list){
        // console.log(el.name)
        var tmpName = el.name.split('.')[1];
        if (tmpName === 'system' ) { //let's not show system.indexes collections
          delete list[i];
        }

        // Remove dbName  
        el.name = el.name.replace(dbName + '.', '');

      })
      model.set('collections', names);
      if (names.length>0 && names[0]) model.set('collectionName', names[0].name)
      // model.subscribe('collections', function() {
      // console.log(model.get('collections'))
      done();
      // });
    });
  }
});

mongoui-dbname.patch.zip

@AndyScott77 thank you, but there's a brand new version of MongoUI now. I rebuild it with React and Express, no Derby anymore because that was giving me a hard time