এই জন্য, printjson ব্যবহার করুন. আসুন প্রথমে নথি-
সহ একটি সংগ্রহ তৈরি করি> db.cursorDemo.insertOne({"StudentFullName":"John Smith","StudentAge":23});
{
"acknowledged" : true,
"insertedId" : ObjectId("5cc7f0d08f9e6ff3eb0ce442")
}
> db.cursorDemo.insertOne({"StudentFullName":"John Doe","StudentAge":21});
{
"acknowledged" : true,
"insertedId" : ObjectId("5cc7f0df8f9e6ff3eb0ce443")
}
> db.cursorDemo.insertOne({"StudentFullName":"Carol Taylor","StudentAge":20});
{
"acknowledged" : true,
"insertedId" : ObjectId("5cc7f0eb8f9e6ff3eb0ce444")
}
> db.cursorDemo.insertOne({"StudentFullName":"Chris Brown","StudentAge":24});
{
"acknowledged" : true,
"insertedId" : ObjectId("5cc7f0f88f9e6ff3eb0ce445")
} Find() পদ্ধতির সাহায্যে একটি সংগ্রহ থেকে সমস্ত নথি প্রদর্শন করার জন্য নিম্নলিখিত প্রশ্ন রয়েছে -
> db.cursorDemo.find().pretty();
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{
"_id" : ObjectId("5cc7f0d08f9e6ff3eb0ce442"),
"StudentFullName" : "John Smith",
"StudentAge" : 23
}
{
"_id" : ObjectId("5cc7f0df8f9e6ff3eb0ce443"),
"StudentFullName" : "John Doe",
"StudentAge" : 21
}
{
"_id" : ObjectId("5cc7f0eb8f9e6ff3eb0ce444"),
"StudentFullName" : "Carol Taylor",
"StudentAge" : 20
}
{
"_id" : ObjectId("5cc7f0f88f9e6ff3eb0ce445"),
"StudentFullName" : "Chris Brown",
"StudentAge" : 24
} প্রিন্টজসন −
দিয়ে ডকুমেন্টের পুনরাবৃত্তি এবং প্রিন্ট করার জন্য নিচের প্রশ্নটি রয়েছে> db.cursorDemo.find().forEach(printjson);
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{
"_id" : ObjectId("5cc7f0d08f9e6ff3eb0ce442"),
"StudentFullName" : "John Smith",
"StudentAge" : 23
}
{
"_id" : ObjectId("5cc7f0df8f9e6ff3eb0ce443"),
"StudentFullName" : "John Doe",
"StudentAge" : 21
}
{
"_id" : ObjectId("5cc7f0eb8f9e6ff3eb0ce444"),
"StudentFullName" : "Carol Taylor",
"StudentAge" : 20
}
{
"_id" : ObjectId("5cc7f0f88f9e6ff3eb0ce445"),
"StudentFullName" : "Chris Brown",
"StudentAge" : 24
} আমরা যদি শুধুমাত্র “StudentFullName” এবং “StudentAge” −
ক্ষেত্রগুলির মত নির্দিষ্ট ক্ষেত্র চাই তাহলে দ্বিতীয় প্রশ্নটি হল> db.cursorDemo.find({}, { "StudentFullName": 1,"StudentAge":1, "_id": 0 }).forEach(printjson) এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{ "StudentFullName" : "John Smith", "StudentAge" : 23 }
{ "StudentFullName" : "John Doe", "StudentAge" : 21 }
{ "StudentFullName" : "Carol Taylor", "StudentAge" : 20 }
{ "StudentFullName" : "Chris Brown", "StudentAge" : 24 }