Created
January 22, 2012 00:25
-
-
Save tobyhede/1654708 to your computer and use it in GitHub Desktop.
node.js spaghetti
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// From: https://github.com/christkv/node-mongodb-native | |
// Not picking on the driver itself, it appears to be idiomatic node javascript | |
// Custom factory (need to provide a 12 byte array); | |
CustomPKFactory = function() {} | |
CustomPKFactory.prototype = new Object(); | |
CustomPKFactory.createPk = function() { | |
return new ObjectID("aaaaaaaaaaaa"); | |
} | |
var p_client = new Db('integration_tests_20', new Server("127.0.0.1", 27017, {}), {'pk':CustomPKFactory}); | |
p_client.open(function(err, p_client) { | |
p_client.dropDatabase(function(err, done) { | |
p_client.createCollection('test_custom_key', function(err, collection) { | |
collection.insert({'a':1}, function(err, docs) { | |
collection.find({'_id':new ObjectID("aaaaaaaaaaaa")}, function(err, cursor) { | |
cursor.toArray(function(err, items) { | |
test.assertEquals(1, items.length); | |
// Let's close the db | |
p_client.close(); | |
}); | |
}); | |
}); | |
}); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Nice!