ক্ষেত্রটি MongoDB-তে একটি সংখ্যা কিনা তা পরীক্ষা করতে, $type অপারেটর ব্যবহার করুন। নিম্নলিখিত বাক্য গঠন
db.yourCollectionName.find({youtFieldName: {$type:"number"}}).pretty(); আসুন প্রথমে ডকুমেন্ট সহ একটি সংগ্রহ তৈরি করি
> db.checkIfFieldIsNumberDemo.insertOne({"StudentName":"John","StudentAge":23});
{
"acknowledged" : true,
"insertedId" : ObjectId("5c9ec75dd628fa4220163b83")
}
>db.checkIfFieldIsNumberDemo.insertOne({"StudentName":"Chris","StudentMathScore":98,"StudentCountryName":"US"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5c9ec77cd628fa4220163b84")
}
>db.checkIfFieldIsNumberDemo.insertOne({"StudentName":"Robert","StudentCountryName":"AUS"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5c9ec7a4d628fa4220163b85")
}
>db.checkIfFieldIsNumberDemo.insertOne({"StudentId":101,"StudentName":"Larry","StudentCountryName":"AUS"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5c9ec7ccd628fa4220163b86")
} Find() পদ্ধতি
এর সাহায্যে একটি সংগ্রহ থেকে সমস্ত নথি প্রদর্শন করার জন্য নিম্নলিখিত প্রশ্ন রয়েছে> db.checkIfFieldIsNumberDemo.find().pretty();
এটি নিম্নলিখিত আউটপুট তৈরি করবে
{
"_id" : ObjectId("5c9ec75dd628fa4220163b83"),
"StudentName" : "John",
"StudentAge" : 23
}
{
"_id" : ObjectId("5c9ec77cd628fa4220163b84"),
"StudentName" : "Chris",
"StudentMathScore" : 98,
"StudentCountryName" : "US"
}
{
"_id" : ObjectId("5c9ec7a4d628fa4220163b85"),
"StudentName" : "Robert",
"StudentCountryName" : "AUS"
}
{
"_id" : ObjectId("5c9ec7ccd628fa4220163b86"),
"StudentId" : 101,
"StudentName" : "Larry",
"StudentCountryName" : "AUS"
} একটি ক্ষেত্র একটি সংখ্যা কিনা তা পরীক্ষা করার জন্য নিম্নোক্ত ক্যোয়ারী
> db.checkIfFieldIsNumberDemo.find({StudentMathScore: {$type:"number"}}).pretty(); নিচের আউটপুটটি ক্ষেত্রটি প্রদর্শন করে যা একটি সংখ্যা অর্থাৎ StudentMathScore
{
"_id" : ObjectId("5c9ec77cd628fa4220163b84"),
"StudentName" : "Chris",
"StudentMathScore" : 98,
"StudentCountryName" : "US"
}