2
ちょうどMongoDBのドライバからのサンプルコードを見て: http://mongodb.github.io/node-mongodb-native/2.2/tutorials/projections/node.jsコールバック関数にエラーがなければnullが必要ですか?
var MongoClient = require('mongodb').MongoClient
, assert = require('assert');
// Connection URL
var url = 'mongodb://localhost:27017/test';
// Use connect method to connect to the server
MongoClient.connect(url, function(err, db) {
assert.equal(null, err);
console.log("Connected correctly to server");
findDocuments(db, function() {
db.close();
});
});
var findDocuments = function(db, callback) {
// Get the documents collection
var collection = db.collection('restaurants');
// Find some documents
collection.find({ 'cuisine' : 'Brazilian' }, { 'name' : 1, 'cuisine' : 1 }).toArray(function(err, docs) {
assert.equal(err, null);
console.log("Found the following records");
console.log(docs)
callback(docs);
});
}
Shouln't最後の行のコールバック(ドキュメント)コールバック(NULL、ドキュメント)も?
node.jsのコールバック表記によると、開発者は独自のスタイルを使用できます。このスタイルでは、コールバックは 'error'をまったく受け入れません。 – alexmac