1

Is there a way to unset a const in the mongo shell.

When trying the delete operator, I get the following output:

> const myconst = {"test":123}
> myconst
{ "test" : 123 }
> delete myconst
false
>
Naman Kumar
  • 456
  • 1
  • 4
  • 12
  • Well, `const` declares a **constant** which namely never changes. In order to unset a **variable** see https://stackoverflow.com/questions/1596782/how-to-unset-a-javascript-variable – Wernfried Domscheit Mar 04 '21 at 13:13
  • @WernfriedDomscheit i understand that concept but if my server is running and i have got lots of these consts in the memory now i want to deallocate them what can i do then. As one way i suppose would be stopping the server and restarting it. – Naman Kumar Mar 04 '21 at 13:15
  • I doubt that a bunch of constant could stress your server. Other use `const` onl for **contants** rather than for variables. Apart from that: disconnect or closing your shell should be sufficient. Stopping the server should not have any effect on local variables. – Wernfried Domscheit Mar 04 '21 at 13:53

0 Answers0