হ্যাঁ, আপনি findOne() ব্যবহার করতে পারেন। নিচের সিনট্যাক্স −
db.yourCollectionName.findOne();
আপনি toArray() পাশাপাশি −
ব্যবহার করতে পারেনdb.yourCollectionName.find().toArray();
আসুন প্রথমে নথি-
সহ একটি সংগ্রহ তৈরি করি> db.betterFormatDemo.insertOne({"StudentName":"Adam Smith","StudentScores":[98,67,89]});
{
"acknowledged" : true,
"insertedId" : ObjectId("5cd7ab826d78f205348bc640")
}
> db.betterFormatDemo.insertOne({"StudentName":"John Doe","StudentScores":[67,89,56]});
{
"acknowledged" : true,
"insertedId" : ObjectId("5cd7ab936d78f205348bc641")
}
> db.betterFormatDemo.insertOne({"StudentName":"Sam Williams","StudentScores":[45,43,33]});
{
"acknowledged" : true,
"insertedId" : ObjectId("5cd7aba76d78f205348bc642")
} Find() পদ্ধতির সাহায্যে একটি সংগ্রহ থেকে সমস্ত নথি প্রদর্শন করার জন্য নিম্নলিখিত প্রশ্ন রয়েছে -
> db.betterFormatDemo.find();
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{ "_id" : ObjectId("5cd7ab826d78f205348bc640"), "StudentName" : "Adam Smith", "StudentScores" : [ 98, 67, 89 ] }
{ "_id" : ObjectId("5cd7ab936d78f205348bc641"), "StudentName" : "John Doe", "StudentScores" : [ 67, 89, 56 ] }
{ "_id" : ObjectId("5cd7aba76d78f205348bc642"), "StudentName" : "Sam Williams", "StudentScores" : [ 45, 43, 33 ] } কেস 1 − findOne().
ব্যবহার করেMongoDB ফলাফলগুলিকে আরও ভাল বিন্যাসে প্রদর্শন করার জন্য নিম্নোক্ত ক্যোয়ারী −
> db.betterFormatDemo.findOne();
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{
"_id" : ObjectId("5cd7ab826d78f205348bc640"),
"StudentName" : "Adam Smith",
"StudentScores" : [
98,
67,
89
]
} কেস 2 − find().toArray().
ব্যবহার করেMongoDB ফলাফলগুলিকে আরও ভাল বিন্যাসে প্রদর্শন করার জন্য নিম্নোক্ত ক্যোয়ারী −
> db.betterFormatDemo.find().toArray();
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে[
{
"_id" : ObjectId("5cd7ab826d78f205348bc640"),
"StudentName" : "Adam Smith",
"StudentScores" : [
98,
67,
89
]
},
{
"_id" : ObjectId("5cd7ab936d78f205348bc641"),
"StudentName" : "John Doe",
"StudentScores" : [
67,
89,
56
]
},
{
"_id" : ObjectId("5cd7aba76d78f205348bc642"),
"StudentName" : "Sam Williams",
"StudentScores" : [
45,
43,
33
]
}
]