इसी तरह के ऑपरेशन के लिए, आप / searchLetter / का उपयोग कर सकते हैं। आइए पहले दस्तावेजों के साथ एक संग्रह बनाएं -
> db.demo26.insertOne({"StudentName":"Chris"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e14c9dc22d07d3b95082e79")
}
> db.demo26.insertOne({"StudentName":"John"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e14c9e022d07d3b95082e7a")
}
> db.demo26.insertOne({"StudentName":"Jones"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e14ca7222d07d3b95082e7b")
}
> db.demo26.insertOne({"StudentName":"David"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e14ca7622d07d3b95082e7c")
} संग्रह से सभी दस्तावेज़ों को खोजने () विधि की सहायता से प्रदर्शित करें -
> db.demo26.find();
यह निम्नलिखित आउटपुट देगा -
{ "_id" : ObjectId("5e14c9dc22d07d3b95082e79"), "StudentName" : "Chris" }
{ "_id" : ObjectId("5e14c9e022d07d3b95082e7a"), "StudentName" : "John" }
{ "_id" : ObjectId("5e14ca7222d07d3b95082e7b"), "StudentName" : "Jones" }
{ "_id" : ObjectId("5e14ca7622d07d3b95082e7c"), "StudentName" : "David" } MongoDB में "LIKE" कथन का उपयोग करने के लिए क्वेरी निम्नलिखित है -
> db.demo26.find({"StudentName":/Jo/}); यह निम्नलिखित आउटपुट देगा -
{ "_id" : ObjectId("5e14c9e022d07d3b95082e7a"), "StudentName" : "John" }
{ "_id" : ObjectId("5e14ca7222d07d3b95082e7b"), "StudentName" : "Jones" }