0
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安裝托架的NodeJS:安裝托架5.5但例如用錯誤崩潰
npm install cradle
誤差輸出行駛node cradle.js
[email protected]:~# 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)
UPDATE:問題歸結爲
db.get('vader', function (err, doc) {
doc.name;
assert.equal(doc.force, 'dark');
});
它在抱怨doc.name
我在哪裏可以查看數據庫這樣我就可以看到添加新行?
我已經更新的問題。 – KJW 2011-06-12 17:55:57
@KimJongWoo更新了答案。你確實安裝了沙發嗎? ;) – Raynos 2011-06-12 18:00:18
是的,但我不知道它是否在運行或它正在運行。我正在使用ubuntu 9 – KJW 2011-06-12 18:06:52