Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 0.81 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // Custom factory (need to provide a 12 byte array);
  2. CustomPKFactory = function() {}
  3. CustomPKFactory.prototype = new Object();
  4. CustomPKFactory.createPk = function() {
  5.   return new ObjectID("aaaaaaaaaaaa");
  6. }
  7.  
  8. var p_client = new Db('integration_tests_20', new Server("127.0.0.1", 27017, {}), {'pk':CustomPKFactory});
  9. p_client.open(function(err, p_client) {
  10.   p_client.dropDatabase(function(err, done) {
  11.     p_client.createCollection('test_custom_key', function(err, collection) {
  12.       collection.insert({'a':1}, function(err, docs) {
  13.         collection.find({'_id':new ObjectID("aaaaaaaaaaaa")}, function(err, cursor) {
  14.           cursor.toArray(function(err, items) {
  15.             test.assertEquals(1, items.length);
  16.  
  17.             // Let's close the db
  18.             p_client.close();
  19.           });
  20.         });
  21.       });
  22.     });
  23.   });
  24. });