একটি স্ট্রিং থেকে স্বতন্ত্র প্রথম শব্দ পেতে, আপনি distinct() ব্যবহার করতে পারেন। আসুন প্রথমে নথি-
সহ একটি সংগ্রহ তৈরি করি> db.distinctFirstWordDemo.insertOne(
{
"_id": 100,
"StudentName":"John",
"StudentFeature": "John is a good player",
"Subject":"MongoDB"
}
);
{ "acknowledged" : true, "insertedId" : 100 }
> db.distinctFirstWordDemo.insertOne(
{
"_id": 101,
"StudentName":"Carol",
"StudentFeature": "Carol is not a good player",
"Subject":"MongoDB"
}
);
{ "acknowledged" : true, "insertedId" : 101 } Find() পদ্ধতি -
এর সাহায্যে একটি সংগ্রহ থেকে সমস্ত নথি প্রদর্শন করুন> db.distinctFirstWordDemo.find().pretty();
এটি নিম্নলিখিত আউটপুট −
তৈরি করবে{
"_id" : 100,
"StudentName" : "John",
"StudentFeature" : "John is a good player",
"Subject" : "MongoDB"
}
{
"_id" : 101,
"StudentName" : "Carol",
"StudentFeature" : "Carol is not a good player",
"Subject" : "MongoDB"
} একটি স্ট্রিং −
থেকে স্বতন্ত্র প্রথম শব্দ পেতে ক্যোয়ারীটি নিচে দেওয়া হল> student = db.distinctFirstWordDemo.distinct("StudentFeature", {"Subject" : "MongoDB"}).map(function(st){
return st.split(" ")[0];
});
[ "John", "Carol" ]
> printjson(student); এটি নিম্নলিখিত আউটপুট −
তৈরি করবে[ "John", "Carol" ]