Skip to content
This repository has been archived by the owner on Nov 5, 2018. It is now read-only.

Not Saving/Inserting? #72

Closed
oldramen opened this issue May 16, 2012 · 3 comments
Closed

Not Saving/Inserting? #72

oldramen opened this issue May 16, 2012 · 3 comments
Labels

Comments

@oldramen
Copy link

Okay, so I'm using couchdb + node.js to make a bot in a pet capacity.
i.e., you an use text commands to level it up, teach it tricks, and so on and so forth.
Or at least that's the idea, as I can't seem to get couchdb to work. I'm not a big
fan of the RAM useage of MySQL, and mongo ticks me off to no end, but couch
seems relatively easy.

I've tried felix-couchdb, and cradle, but nano works best for me.

Basically, through calling other functions, vars change. Primarily 'exp' and 'level'.
However, when these change, and mSave(); (the function to insert, see below)
is called, the changes aren't noted. Let's say it saves with Level:2 and Exp:50.
When I restart the node process, and it gets the information, it has the default value of 0.

global.mDBName = 'pet2';
global.mHunger = 100;
global.mExp = 0;
global.mLevel = 0;
global.mName = 'BotOne';
global.mType = 1;
global.mUserId = '4fb1c582aaa5cd1b4900001e';

Log("Connecting to couchdb");
global.nano = require('nano')('http://localhost:5984');

Log("Finding database");
nano.db.create(mDBName, function(a) { a ? Log("db found, connecting") : Log("db not found, creating")
});

global.mSave = function() {
  store.insert({name:mName, type:mType, exp:mExp, hunger:mHunger, level:mLevel}, mUserId, function(a, b) {
    a || console.log(a)
  })
  Log('Bot Saved')
};

store.get(mUserId, function(b, a) {
    if(b && "not_found" == b.error) {
      mSave(), Log("Doc not found, creating")
    }else {
      if(b) {
        return console.log(b)
      }
      Log("Connected to doc: name:" + a.name + ", type:" + a.type + ", level:" + a.level + ", exp:" + a.exp + ", hunger:" + a.hunger);
      mHunger = a.hunger;
      mExp = a.exp;
      mLevel = a.level
    }
  });
@oldramen
Copy link
Author

Fixed by watching the screencast tutorial, and updating mSave:

global.mSave = function() {
  store.get(mUserId, function(b, a) { if(b) { return console.log(b) }
    a.name = mName;a.type = mType;a.exp = mExp;a.hunger = mHunger;a.level = mLevel;
    store.insert(a, function(a) { if(a) { return console.log(a) }
      Log("Bot Saved");
    })
  })
};

@dscape
Copy link
Contributor

dscape commented May 16, 2012

Self fixing issues! Love it!

Thanks for using nano, feel free to add your project to the wiki when you are closer to finished!

Good luck

@oldramen
Copy link
Author

Will do! And yeah, I'm far too lazy to sit around and have other people fix my problems for me. I post issues when I have them, then spend the time trying to fix them. If someone posts before I do, then great! And yeah, one I get around to it, I'd be happy to post it on the wiki!

KangTheTerrible pushed a commit to KangTheTerrible/nano that referenced this issue Aug 19, 2018
Add couchdb 2.* index creation support
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants