Advertisement
Guest User

exports.add_user

a guest
May 9th, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. exports.add_user = function(login, password, callback) {
  2.     var result;
  3.     MongoClient.connect('mongodb://127.0.0.1:27017/test', function(err, db) {
  4.         var collection = db.collection('users');
  5.         collection.find({
  6.             'login': login
  7.         }, function(err, cursor) {
  8.             cursor.toArray(function(err, items) {
  9.                 if (items.length == 0) {
  10.                     collection.insert({
  11.                         login: login,
  12.                         password: password
  13.                     })
  14.                     callback(true);
  15.  
  16.                 } else {
  17.                     callback(false);
  18.                 }
  19.             });
  20.         });
  21.  
  22.         //db.close();
  23.     });
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement