Home  >  Article  >  Database  >  How to define aliases in MongoDB Shell?

How to define aliases in MongoDB Shell?

王林
王林forward
2023-09-13 10:41:061358browse

如何在 MongoDB Shell 中定义别名?

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete