How to clear collection or comments and names on screen from console
I am using the following code to insert data into mongo and I am wondering how I can destroy the whole thing from the console so that my page is not cluttered. I guess I would also like to know how to selectively delete so that I can select the comment name entries and delete them.
live at http://tuts.meteor.com
Messages = new Meteor.Collection('messages');
if (Meteor.is_client){
////////// Helpers for in-place editing //////////
// Returns an event_map key for attaching "ok/cancel" events to
// a text input (given by selector)
var okcancel_events = function (selector) {
return 'keyup '+selector+', keydown '+selector+', focusout '+selector;
};
// Creates an event handler for interpreting "escape", "return", and "blur"
// on a text field and calling "ok" or "cancel" callbacks.
var make_okcancel_handler = function (options) {
var ok = options.ok || function () {};
var cancel = options.cancel || function () {};
return function (evt) {
if (evt.type === "keydown" && evt.which === 27) {
// escape = cancel
cancel.call(this, evt);
} else if (evt.type === "keyup" && evt.which === 13) {
// blur/return/enter = ok/submit if non-empty
var value = String(evt.target.value || "");
if (value)
ok.call(this, value, evt);
else
cancel.call(this, evt);
}
};
};//added as test
Template.entry.events = {};
/* Template.entry.events[okcancel_events('#messageBox')] = make_okcancel_handler({
ok:function(text, event){
var nameEntry = document.getElementById('name');
if(nameEntry.value != ""){
var ts = Date.now() / 1000;
Messages.insert({name: nameEntry.value, message: text, time: ts});
event.target.value = "";
}//if statment ends
}
});
*/
Template.entry.events['click #submit'] = function() {
var nameEntry = document.getElementById('name');
if(nameEntry.value != ""){
var ts = Date.now() / 1000;
Messages.insert({name: nameEntry.value, message: $('#messageBox').val(), time: ts});
}
}
Template.messages.messages = function () {
return Messages.find({}, { sort: {time: -1} });
};
}
source to share
meteor reset
To remove each one on demand using os console
meteor mongo
db.collectionname.remove({query})
Or you could just do it from the chrome / safari / firebug console if your collection is exposed to the client and you can create a UI and use:
collectionname.remove({query})
Advice:
You can use regexp to speed up and delete sets of documents that match a regular expression. for example if I want to remove all values containing 'the' for a field name
. This will work on mongo console, server and client.
collectionname.remove({ name : { $regex: 'the', $options: 'i' }});
The parameter i
makes the case case insensitive.
Of course, collecionname
it's just a placeholder for whatever collection you choose to hit.
source to share