manuelbieh

Untitled

Nov 27th, 2012
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var ObjectID = require('mongodb').ObjectID;
  2. var mongojs = require('mongojs');
  3. var db = mongojs('webcontrol', ['users']);
  4.  
  5. /*
  6. db.users.save({
  7.   name: 'Manuel',
  8.   pass: 'foo',
  9.   channels: [],
  10.   clients: []
  11. });
  12. */
  13.  
  14. //db.users.update({name: 'Manuel'}, {$push: {channels : {name: +new Date(), 'socket_id': 1, 'channel_id': 1}}});
  15.  
  16. //db.users.ensureIndex({ "name": 1 }, { unique: true });
  17.  
  18. /*
  19. db.users.update({name: 'Manuel'}, {$pull: {"channels": {"name": 1353879484674, "socket_id": 1, "channel_id": 1}}}, function(err, docs) {
  20.     console.log('UPDATED ' + JSON.stringify(docs));
  21.     console.log(docs);
  22. });
  23. */
  24.  
  25. db.users.find({name: 'Manuel'}, function(err, docs) {
  26.  
  27.     console.log('Found ' + docs.length + ' document(s)');
  28.  
  29.     docs.forEach(function(doc) {
  30.  
  31.         console.log(doc);
  32.  
  33.         doc.channels.forEach(function(channel_data) {
  34.  
  35.             if(channel_data.name == 1353933194112) {
  36.                 console.log('Removing channel.name ' + 1353933194112);
  37.                 //db.users.update({name: 'Manuel'}, {$pull: {channels: channel_data}});
  38.                 console.log(JSON.stringify({$pull: {channels: channel_data}}));
  39.             }
  40.  
  41.         });
  42.  
  43.     });
  44.  
  45.     db.close();
  46.  
  47. });
Advertisement
Add Comment
Please, Sign In to add comment