
- 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
Add MD5 hash value to MongoDB collection?
To add MD5 hash value, use hex_md5(). Let us first create a collection with documents −
>db.addMd5HashValueDemo.insertOne({"UserName":"Adam","UserPassword":"Adam123456"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd6a4c66d78f205348bc619") } >db.addMd5HashValueDemo.insertOne({"UserName":"Chris","UserPassword":"Chris_121#"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd6a4e46d78f205348bc61a") }
Following is the query to display all documents from a collection with the help of find() method −
> db.addMd5HashValueDemo.find();
This will produce the following output −
{ "_id" : ObjectId("5cd6a4c66d78f205348bc619"), "UserName" : "Adam", "UserPassword" : "Adam123456" } { "_id" : ObjectId("5cd6a4e46d78f205348bc61a"), "UserName" : "Chris", "UserPassword" : "Chris_121#" }
Following is the query to add md5 hash value to mongo collection −
> db.addMd5HashValueDemo.find().forEach( function(documentPass){ documentPass.Value = hex_md5(documentPass.UserPassword); db.addMd5HashValueDemo.save(documentPass); });
Let us check the document once again −
> db.addMd5HashValueDemo.find();
This will produce the following output −
{ "_id" : ObjectId("5cd6a4c66d78f205348bc619"), "UserName" : "Adam", "UserPassword" : "Adam123456", "Value" : "6523857c2bf79b63fd5fa0322575f7be" } { "_id" : ObjectId("5cd6a4e46d78f205348bc61a"), "UserName" : "Chris", "UserPassword" : "Chris_121#", "Value" : "3391ccbe33624258cafa23aa50301615" }
- Related Articles
- MD5 hash encoding using Python?
- Script to add a single value to array in MongoDB collection?
- Golang program to add items into the hash collection
- How to add a column in MongoDB collection?
- Golang program to get key based on value from the hash collection
- Sort MongoDB Collection by Array value?
- Add new field to every document in a MongoDB collection?
- Add field that is unique index to collection in MongoDB?
- Golang program to check a value exists in the hash collection or not
- Golang program to create a hash collection
- MongoDB query to add a document in an already created collection
- Golang program to print the inverted hash collection
- How to add a new value to a collection in Laravel?
- Golang program to convert the hash collection into string
- Golang program to get keys from a hash collection

Advertisements