Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

add generateId.js

  • Loading branch information...
commit 9dd82ba42598e4ab4b728f4fe7989adec29fbbf9 1 parent a851938
Gui Lin authored

Showing 1 changed file with 33 additions and 0 deletions. Show diff stats Hide diff stats

  1. +33 0 examples/generateId.js
33 examples/generateId.js
... ... @@ -0,0 +1,33 @@
  1 +var mongo = require('../index.js')
  2 + , redis = require('redis').createClient()
  3 + , shorten = require('shorten')(redis)
  4 + , async = require('async')
  5 + , db = mongo.db('localhost/test')
  6 + ;
  7 +
  8 +db.bind('system.js');
  9 +db.bind('user');
  10 +
  11 +function log(err) {
  12 + if(err) {
  13 + console.log(err.stack);
  14 + }
  15 +}
  16 +
  17 +function createUser(user, callback) {
  18 +
  19 + async.waterfall([
  20 + function(fn) {
  21 + shorten.nextId('user', fn);
  22 + }
  23 + , function(uid, fn) {
  24 + user.uid = uid;
  25 + db.user.save(user, fn);
  26 + }
  27 + ], callback);
  28 +
  29 +}
  30 +
  31 +for(var i = 0; i<10; i++) {
  32 + createUser({name: 'user' + i}, log);
  33 +}

0 comments on commit 9dd82ba

Please sign in to comment.
Something went wrong with that request. Please try again.