To define an alias in the MongoDB shell you can use the following syntax -
Object.defineProperty(this, 'yourFunctionName', { get: function() { yourStatement1, . . return N }, enumerable: true, configurable: true });
The following is the syntax for assignment using var -
var anyAliasName=yourFunctionName;
Let We implement the above syntax to define aliases in the MongoDB shell. Here, "displayMessageDemo" is our function -
> Object.defineProperty(this, 'displayMessageDemo', { ... get: function() { ... return "Hello MongoDB" ... }, ... enumerable: true, ... configurable: true ... });
Query to assign function to var in MongoDB shell -
> var myMessage = displayMessageDemo;
Let us display the value of the above alias -
> myMessage;
This will produce the following output -
Hello MongoDB
The above is the detailed content of How to define aliases in MongoDB Shell?. For more information, please follow other related articles on the PHP Chinese website!