Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add generateId.js

  • Loading branch information...
commit 9dd82ba42598e4ab4b728f4fe7989adec29fbbf9 1 parent a851938
@guileen authored
Showing with 33 additions and 0 deletions.
  1. +33 −0 examples/generateId.js
View
33 examples/generateId.js
@@ -0,0 +1,33 @@
+var mongo = require('../index.js')
+ , redis = require('redis').createClient()
+ , shorten = require('shorten')(redis)
+ , async = require('async')
+ , db = mongo.db('localhost/test')
+ ;
+
+db.bind('system.js');
+db.bind('user');
+
+function log(err) {
+ if(err) {
+ console.log(err.stack);
+ }
+}
+
+function createUser(user, callback) {
+
+ async.waterfall([
+ function(fn) {
+ shorten.nextId('user', fn);
+ }
+ , function(uid, fn) {
+ user.uid = uid;
+ db.user.save(user, fn);
+ }
+ ], callback);
+
+}
+
+for(var i = 0; i<10; i++) {
+ createUser({name: 'user' + i}, log);
+}

0 comments on commit 9dd82ba

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