Reputation: 4631
When working with the interactive shell in MongoDB, I define variables and functions.
function f(x) { return x * x}
obj = {"name": "peter"}
Removing single variables from the session works with:
delete obj
I couldn't find out how to remove functions from the session:
delete f()
... did not work.
Is it somehow possible to clear all defined variables and functions? I tried e.g.:
delete {}
delete({})
...
But nothing worked.
Upvotes: 1
Views: 305
Reputation: 11671
There isn't a way to clear out all defined function and variables. I don't think there's actually a difference between user- and system- defined functions anyway. You can replace predefined functions with your own- does that now count as user defined and should be deleted? Or should it be reset? If you want to clear everything out, just close and reopen the shell.
If you want to clear out a function, you can define it with a different but common javascript idiom as a variable assigned a value that is an anonymous function:
> noop = function() { }
> delete noop
Upvotes: 3