开发者

NodeJS: installed cradle 5.5 but example crashes with error

开发者 https://www.devze.com 2023-03-12 23:02 出处:网络
var cradle = require(\'cradle\'); var db = new(cradle.Connection)().database(\'starwars\'); db.get(\'vader\', function (err, doc) {
var cradle = require('cradle');
var db = new(cradle.Connection)().database('starwars');

db.get('vader', function (err, doc) {
    doc.name;
    assert.equal(doc开发者_JAVA技巧.force, 'dark');
});

db.save('skywalker', {
    force: 'light',
    name: 'Luke Skywalker'
}, function (err, res) {
    if (err) {
        // Handle error
    } else {
        // Handle success
    }
});

installed cradle via npm

npm install cradle

The error output running 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)

UPDATE: problem boils down to

db.get('vader', function (err, doc) {
        doc.name;
        assert.equal(doc.force, 'dark');
    });

it's complaining about doc.name

Where can I view the database so I can see the new row added?


db.get('vader', function (err, doc) {
    if (err) {
        console.log(err);
    } else {
        doc.name;
        assert.equal(doc.force, 'dark');
    }
});

The example doesn't do error handling. I would assume the error is document vader doesn't exist or database starwars doesn't exist.

If you have couch installed and running then the database lives at http://localhost:5984/_utils/

0

精彩评论

暂无评论...
验证码 换一张
取 消