var cradle = require('cradle');
var db = new(cradle.Connection)().database('starwars');
db.get('vader', function (err, doc) {
doc.name;
assert.equal(doc.force, 'dark');
});
db.save('skywalker', {
force: 'light',
name: 'Luke Skywalker'
}, function (err, res) {
if (err) {
// Handle error
} else {
// Handle success
}
});
通过npm 安装支架
npm install cradle
运行node cradle.js
的错误输出
root@server:~# node cradle.js
/root/cradle.js:5
doc.name;
^
TypeError: Cannot read property 'name' of undefined
at Object.callback (/root/cradle.js:5:8)
at /root/node_modules/cradle/lib/cradle.js:276:26
at IncomingMessage.<anonymous> (/root/node_modules/cradle/lib/cradle.js:210:21)
at IncomingMessage.emit (events.js:81:20)
at HTTPParser.onMessageComplete (http.js:133:23)
at Socket.ondata (http.js:1213:22)
at Socket._onReadable (net.js:681:27)
at IOWatcher.onReadable [as callback] (net.js:177:10)
更新:问题归结为
db.get('vader', function (err, doc) {
doc.name;
assert.equal(doc.force, 'dark');
});
它在抱怨doc.name
在哪里可以查看数据库以便查看添加的新行?
db.get('vader', function (err, doc) {
if (err) {
console.log(err);
} else {
doc.name;
assert.equal(doc.force, 'dark');
}
});
该示例不进行错误处理。我认为错误是文档vader
不存在或数据库starwars
不存在。
如果你安装了沙发并在运行,那么数据库位于http://localhost:5984/_utils/