![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
MongoDB query to store File Name and location?
To store, let us see an example and create a collection with documents −
> db.demo645.insertOne( ... { ... 'fileName' : 'MongoDB Program', ... 'fileLocation':'C:/users/workspace/AllMongoDBProgram/MongoDB Program' ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e9c78f36c954c74be91e6e8") } > > db.demo645.insertOne( ... { ... 'fileName' : 'SumOfTwoNumbers.java', ... 'fileLocation':'E:/eclipseWorkspace/AllJavaPrograms/SumOfTwoNumbers.java' ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e9c78f36c954c74be91e6e9") } > db.demo645.insertOne( ... { ... 'fileName' : 'Script.sql', ... 'fileLocation':'C:/MySQLQuery/Script.sql' ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e9c78f46c954c74be91e6ea") }
Display all documents from a collection with the help of find() method −
> db.demo645.find();
This will produce the following output −
{ "_id" : ObjectId("5e9c78f36c954c74be91e6e8"), "fileName" : "MongoDB Program", "fileLocation" : "C:/users/workspace/AllMongoDBProgram/MongoDB Program" } { "_id" : ObjectId("5e9c78f36c954c74be91e6e9"), "fileName" : "SumOfTwoNumbers.java", "fileLocation" : "E:/eclipseWorkspace/AllJavaPrograms/SumOfTwoNumbers.java" } { "_id" : ObjectId("5e9c78f46c954c74be91e6ea"), "fileName" : "Script.sql", "fileLocation" : "C:/MySQLQuery/Script.sql" }
Advertisements