【发布时间】:2018-06-08 19:56:11
【问题描述】:
我正在尝试创建一个名为“_users”的简单数据库,并使用 Couch-DB 将新用户插入其中。
我在 shell 中使用 Node 来运行以下代码:
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);
});
}
};
节点复制
> 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.
运行此程序后,我希望在/_users/cheese 看到一个条目,但不存在任何条目。我做错了什么吗?
【问题讨论】:
-
1.预期的条目应该是 /_users/org.couchdb.user:cheese 2. usersDB.insert 回调的响应是什么?
-
@AlexisCôté 当我转到
/_users/org.couchdb.user:cheese时,我看到了{"error":"not_found","reason":"missing"}。回调没有响应;正如你在上面的 shell 中看到的,它只是返回 undefined。 -
nano.db.destroy和nano.db.create函数使用回调 - API 调用在移动到下一个调用之前解决了吗?
标签: javascript node.js nosql couchdb couchdb-nano