Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var ObjectID = require('mongodb').ObjectID;
- var mongojs = require('mongojs');
- var db = mongojs('webcontrol', ['users']);
- /*
- db.users.save({
- name: 'Manuel',
- pass: 'foo',
- channels: [],
- clients: []
- });
- */
- //db.users.update({name: 'Manuel'}, {$push: {channels : {name: +new Date(), 'socket_id': 1, 'channel_id': 1}}});
- //db.users.ensureIndex({ "name": 1 }, { unique: true });
- /*
- db.users.update({name: 'Manuel'}, {$pull: {"channels": {"name": 1353879484674, "socket_id": 1, "channel_id": 1}}}, function(err, docs) {
- console.log('UPDATED ' + JSON.stringify(docs));
- console.log(docs);
- });
- */
- db.users.find({name: 'Manuel'}, function(err, docs) {
- console.log('Found ' + docs.length + ' document(s)');
- docs.forEach(function(doc) {
- console.log(doc);
- doc.channels.forEach(function(channel_data) {
- if(channel_data.name == 1353933194112) {
- console.log('Removing channel.name ' + 1353933194112);
- //db.users.update({name: 'Manuel'}, {$pull: {channels: channel_data}});
- console.log(JSON.stringify({$pull: {channels: channel_data}}));
- }
- });
- });
- db.close();
- });
Advertisement
Add Comment
Please, Sign In to add comment