Skip to content

Instantly share code, notes, and snippets.

@tobyhede
Created January 22, 2012 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobyhede/1654708 to your computer and use it in GitHub Desktop.
Save tobyhede/1654708 to your computer and use it in GitHub Desktop.
node.js spaghetti
// 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();
});
});
});
});
});
});
@frhd
Copy link

frhd commented Apr 29, 2014

Nice!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment