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

db.getSortedSetRange is not a function #183

Open
fidelix opened this issue Mar 25, 2016 · 4 comments
Open

db.getSortedSetRange is not a function #183

fidelix opened this issue Mar 25, 2016 · 4 comments
Labels

Comments

@fidelix
Copy link
Contributor

fidelix commented Mar 25, 2016

Sorry to bother you again, this is probably something small, and likely my fault.

Here's the simple file I created:

var async = require('async');
var Data = require('../nodebb-plugin-import/server/data.js');
Data.eachPost(console.log,
  function (err) {
    if (err) {
      throw err;
    }
    console.log("DONE!!");
  }
);

When I run it I get this error:

/home/fidelix/www/anbient/forum/node_modules/nodebb-plugin-import/server/data.js:476
                db.getSortedSetRange(setKey, start, end, function(err, ids) {
                   ^

TypeError: db.getSortedSetRange is not a function
    at /home/fidelix/www/anbient/forum/node_modules/nodebb-plugin-import/server/data.js:476:8
    at Object.async.whilst (/home/fidelix/www/anbient/forum/node_modules/nodebb-plugin-import/node_modules/async/lib/async.js:675:13)
    at Object.Data.processIdsSet (/home/fidelix/www/anbient/forum/node_modules/nodebb-plugin-import/server/data.js:468:9)
    at Object.Data.processSet (/home/fidelix/www/anbient/forum/node_modules/nodebb-plugin-import/server/data.js:412:15)
    at Object.Data.each (/home/fidelix/www/anbient/forum/node_modules/nodebb-plugin-import/server/data.js:388:15)
    at Object.Data.eachPost (/home/fidelix/www/anbient/forum/node_modules/nodebb-plugin-import/server/data.js:290:15)
    at Object.<anonymous> (/home/fidelix/www/anbient/forum/node_modules/nodebb-plugin-import-ipboard/ipb.js:4:6)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)

Process finished with exit code 1

Any ideas why it's not defined? Looking at the db object it seems to have the proper configs (mongodb, localhost, etc)...

@akhoury
Copy link
Owner

akhoury commented Mar 25, 2016

i think I know why, i will fix it tomorrow

@akhoury akhoury added the bug label Mar 25, 2016
@akhoury
Copy link
Owner

akhoury commented Mar 27, 2016

hey, I found the issue, but it's NOT** (edit) an easy fix, the thing is that you're trying to use the database before it had some time to load - there is a callback to db.init() but the issue with this one is if you're already running NodeBB at the same-time, the callback would never execute. I have a fix in mind, but it's Easter! so I am give you a very stupid workaround till i fix this the right way, hopefully next week.

timeout way

var async = require('async');
var Data = require('../nodebb-plugin-import/server/data.js');

// just wrap it in a timeout till it's ready.
setTimeout(function() {

  Data.eachPost(console.log,
    function (err) {
      if (err) {
        throw err;
      }
      console.log("DONE!!");
    }
  );

}, 3000); // 3 seconds worked for me, you might need more depending on how large your db-index is.

interval way

var async = require('async');
var Data = require('../nodebb-plugin-import/server/data.js');

var go = function () {
  Data.eachPost(console.log,
    function (err) {
      if (err) {
        throw err;
      }
      console.log("DONE!!");
    }
  );
};
// you can test it every 500ms 
var interval = setInterval(function() {
  if (Data.db.client) {
    clearInterval(interval);
    go();
  }
}, 500);

Both solutions are very stupid, but if you're writing a one-off script, they should work

@fidelix
Copy link
Contributor Author

fidelix commented Mar 28, 2016

Thank you so much @akhoury. This worked!

@fidelix fidelix closed this as completed Mar 28, 2016
@fidelix
Copy link
Contributor Author

fidelix commented Mar 28, 2016

Ops... let me leave it open...

@fidelix fidelix reopened this Mar 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants