MongoDB query to store File Name and location?

MongoDBDatabaseBig Data Analytics

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" }
raja
Published on 12-May-2020 08:36:38
Advertisements