Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to define aliases in the MongoDB Shell?
To define aliases in MongoDB shell, you can use below syntax −
Object.defineProperty(this, 'yourFunctionName', {
get: function() {
yourStatement1,
.
.
return N
},
enumerable: true,
configurable: true
});
Following is the syntax to assign with var −
var anyAliasName=yourFunctionName;
Let us implement the above syntax in order to define an 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 above aliases −
> myMessage;
This will produce the following output −
Hello MongoDB
Advertisements