'_users'라는 간단한 db를 만들고 Couch-DB를 사용하여 새 사용자를 삽입하려고합니다.couchdb 데이터베이스에 삽입 한 후 문서를 찾을 수 없거나 누락되었습니다.
나는 다음과 같은 코드를 실행하는 쉘에서 노드를 사용하고이를 실행 한 후
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);
});
}
};
노드 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.
을, 나는 볼 것으로 예상 입력은 /_users/cheese
이지만 항목이 없습니다. 내가 뭔가 잘못하고 있니?
1. 예상되는 항목은 /_users/org.couchdb.user:cheese이어야합니다. 2. usersDB.insert 콜백의 응답은 무엇입니까? –
@ AlexisCôté'/_users/org.couchdb.user : cheese'에 갈 때'{ "error": "not_found", "reason": "missing"}'이 보입니다. 콜백의 응답이 없습니다. 위의 셸에서 볼 수 있듯이 단순히 정의되지 않은 값을 반환합니다. –
'nano.db.destroy'와'nano.db.create' 함수는 콜백을 사용합니다 - API 호출은 다음 호출로 이동하기 전에 해결 되었습니까? – tephyr