
- MongoDB Tutorial
- MongoDB - Home
- MongoDB - Overview
- MongoDB - Advantages
- MongoDB - Environment
- MongoDB - Data Modeling
- MongoDB - Create Database
- MongoDB - Drop Database
- MongoDB - Create Collection
- MongoDB - Drop Collection
- MongoDB - Data Types
- MongoDB - Insert Document
- MongoDB - Query Document
- MongoDB - Update Document
- MongoDB - Delete Document
- MongoDB - Projection
- MongoDB - Limiting Records
- MongoDB - Sorting Records
- MongoDB - Indexing
- MongoDB - Aggregation
- MongoDB - Replication
- MongoDB - Sharding
- MongoDB - Create Backup
- MongoDB - Deployment
- MongoDB - Java
- MongoDB - PHP
- Advanced MongoDB
- MongoDB - Relationships
- MongoDB - Database References
- MongoDB - Covered Queries
- MongoDB - Analyzing Queries
- MongoDB - Atomic Operations
- MongoDB - Advanced Indexing
- MongoDB - Indexing Limitations
- MongoDB - ObjectId
- MongoDB - Map Reduce
- MongoDB - Text Search
- MongoDB - Regular Expression
- Working with Rockmongo
- MongoDB - GridFS
- MongoDB - Capped Collections
- Auto-Increment Sequence
- MongoDB Useful Resources
- MongoDB - Questions and Answers
- MongoDB - Quick Guide
- MongoDB - Useful Resources
- MongoDB - Discussion
How to unset a variable in MongoDB shell?
Use delete operator to unset variable in MongoDB shell. Following is the syntax −
delete yourVariableName;
Let us now implement the above syntax in order to unset variable in MongoDB shell. First, print the variable name −
> customerDetail;
This will produce the following output −
2019-05-08T22:29:17.361+0530 E QUERY [js] ReferenceError: customerDetail is not defined : @(shell):1:1
Now you can set a value in the above variable. Following is the query −
> customerDetail={"CustomerFirstName":"Chris"};
This will produce the following output −
{ "CustomerFirstName" : "Chris" }
Following is the query to show the value of a variable −
> customerDetail;
This will produce the following output −
{ "CustomerFirstName" : "Chris" }
Following is the query to unset a variable in MongoDB shell −
> delete customerDetail;
This will produce the following output −
true
Let us verify the variable exists or not. If it does not exist then you will get an error otherwise, a value −
> customerDetail;
This will produce the following output −
2019-05-08T22:30:35.530+0530 E QUERY [js] ReferenceError: customerDetail is not defined : @(shell):1:1
- Related Articles
- How to unset a JavaScript variable?
- How to unset objects in MongoDB?
- Variable collection name in MongoDB shell with JavaScript?
- How to terminate a MongoDB shell script earlier?
- How to print document value in MongoDB shell?
- How to define aliases in the MongoDB Shell?
- MongoDB query to $pull / $unset with multiple conditions?
- Unset an attribute from a single array element in MongoDB?
- Storing a Command in a Variable in a Shell Script
- Delete expoted environment Variable in Linux shell
- How to run MongoDB shell using mongos command?\n
- Prettyprint in MongoDB shell as default?
- Format date value in MongoDB shell?
- How to operate on all databases from the MongoDB shell?
- Deleting all records of a collection in MongoDB Shell?

Advertisements