Use result from MongoDB in shell script?

MongoDBDatabaseBig Data Analytics

Let us first create a collection with a document −

>db.useResultDemo.insertOne({"StudentFirstName":"Robert"});
{
   "acknowledged" : true,
   "insertedId" : ObjectId("5cda70f5b50a6c6dd317adcd")
}

Display all documents from a collection with the help of find() method −

> db.useResultDemo.find();

Following is the output −

{ "_id" : ObjectId("5cda70f5b50a6c6dd317adcd"), "StudentFirstName" : "Robert" }

Here is the query to use result from MongoDB in shell script with var keyword −

> var studentName=db.useResultDemo.findOne({},{_id:0});
> studentName

Following is the output −

{ "StudentFirstName" : "Robert" }
raja
Published on 21-May-2019 11:55:49
Advertisements