Advertisement
Guest User

Untitled

a guest
Aug 27th, 2016
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.75 KB | None | 0 0
  1. var mongoose = require("./libs/mongoose");
  2. var User = require("./models/user").User;
  3. var asyng = require('async');
  4.  
  5. asyng.series([
  6. open,
  7. dropDatabase,
  8. createUsers,
  9. close
  10. ],function (err,results) {
  11. if(err) throw err;
  12. console.log(arguments);
  13. });
  14.  
  15. function open(callback) {
  16. mongoose.connection.on('open',callback);
  17. }
  18.  
  19. function dropDatabase(callback) {
  20. var db = mongoose.connection.db;
  21. db.dropDatabase(callback);
  22. }
  23. function createUsers(callback) {
  24. asyng.parallel([
  25. function (callback) {
  26. var vasya = new User({username:'Вася',password: 'supervasay'});
  27. vasya.save(function(err){
  28. callback(err,vasya);
  29. })
  30. },
  31. function (callback) {
  32. var petya = new User({username:'Петя',password: 'superpetya'});
  33. petya.save(function(err){
  34. callback(err,petya);
  35. })
  36. },
  37. function (callback) {
  38. var admin = new User({username:'admin',password: 'superadmin'});
  39. admin.save(function(err){
  40. callback(err,admin);
  41. })
  42. }],callback);
  43.  
  44.  
  45. }
  46. function close(callback) {
  47. mongoose.disconnect(callback);
  48. }
  49.  
  50. function dropDatabase(callback) {
  51. var db = mongoose.connection.db;
  52. db.dropDatabase(callback);
  53. }
  54.  
  55. while (++index < length) {
  56. array[index] = args[start + index];
  57. }
  58. switch (start) {
  59. case 0: return func.call(this, array);
  60. case 1: return func.call(this, args[0], array);
  61. case 2: return func.call(this, args[0], args[1], array);
  62. }
  63. var otherArgs = Array(start + 1);
  64. index = -1;
  65. while (++index < start) {
  66. otherArgs[index] = args[index];
  67. }
  68. otherArgs[start] = array;
  69. return apply(func, this, otherArgs);
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement