I'm trying to create a simple db called '_users' and insert a new user into it using Couch-DB.
I'm using Node in the shell to run the following code:
UserProfile.js
var nano = require('nano')('http://localhost:5984')
module.exports = {
addUser: function(id, name, password){
var usersDB = nano.use('_users')
var options = {
"_id": "org.couchdb.user:"+id,
"name": id,
"roles": [],
"type": "user",
"password": password
}
usersDB.insert(options, function(err, body, header) {
console.log('insert is being called')
if (err) {
console.log(err.message);
return;
}
console.log(body);
});
}
};
node repl
> var nano = require('nano')('http://localhost:5984')
undefined
> var usersdb = nano.db.destroy('_users')
undefined
> var usersdb = nano.db.create('_users')
undefined
> var profile = require('./UserProfile.js')
undefined
> profile.addUser('cheese', 'flubber', 'goat')
undefined
> insert is being called
> OS process timed out.
After running this, I expect to see an entry at /_users/cheese
, but no entry exists. Am I doing something incorrectly?
/_users/org.couchdb.user:cheese
I see{"error":"not_found","reason":"missing"}
. There is no response from the callback; as you can see in my shell above, it simply returns undefined. – Mannonano.db.destroy
andnano.db.create
functions use callbacks - did the API calls resolve before moving to the next call? – Hibernate