私は Node と CouchDb に不慣れで、それを手に入れようとしています。コードを機能させるのに苦労しています。users
テーブルを作成し、新しいユーザーを挿入し、「同時に」別のユーザーを取得したいと思います。
起動時に次のエラーが表示されnode app.js
ます。
antoine@ubuntu:~/projects/couchDb$ node app.js
Database users exists.
{"error":"conflict","reason":"Document update conflict."}
Leaving saveDoc
events.js:48
throw arguments[1]; // Unhandled 'error' event
^
Error: socket hang up
at createHangUpError (http.js:1107:15)
at Socket.onend (http.js:1188:27)
at TCP.onread (net.js:369:26)
そして、これが私のコードです。何か問題がありますか? (getDoc 関数を削除すると、エラーはなくなります) 私は、couchDB 1.0.1 とノード 0.6.12 を使用しています。
およびドキュメントはデータベースjdoe4
にjdoe
既に存在しusers
ます。
var dbHost = "127.0.0.1";
var dbPort = 5984;
var dbName = 'users';
var couchdb = require('felix-couchdb');
var client = couchdb.createClient(dbPort, dbHost);
var user = {
name: {
first: 'John',
last: 'Doe'
}
}
var db = client.db(dbName);
db.exists(function(err, exists) {
if (!exists) {
db.create();
console.log('Database ' + dbName + ' created.');
} else {
console.log('Database ' + dbName + ' exists.');
}
db.saveDoc('jdoe4', user, function(err, doc) {
if( err) {
console.log(JSON.stringify(err));
} else {
console.log('Saved user.');
}
console.log('Leaving saveDoc');
});
db.getDoc('jdoe', function(err,doc) {
if( err) {
console.log(JSON.stringify(err));
} else {
console.log(JSON.stringify(doc));
}
console.log('Leaving getDoc');
});
});