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" }
Updated on: 2020-05-12T08:37:32+05:30

573 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements