किसी फ़ील्ड से लौटाए गए वर्णों की मात्रा को सीमित करने के लिए, MongoDB में $substr का उपयोग करें। आइए दस्तावेजों के साथ एक संग्रह बनाएं -
> db.demo233.insertOne({"Paragraph":"My Name is John Smith.I am learning MongoDB database"});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e41877df4cebbeaebec5146")
}
> db.demo233.insertOne({"Paragraph":"David Miller is a good student and learning Spring and Hibernate Framework."});
{
"acknowledged" : true,
"insertedId" : ObjectId("5e4187d7f4cebbeaebec5147")
} संग्रह से सभी दस्तावेज़ों को खोजने () विधि की सहायता से प्रदर्शित करें -
> db.demo233.find().pretty();
यह निम्नलिखित आउटपुट देगा -
{
"_id" : ObjectId("5e41877df4cebbeaebec5146"),
"Paragraph" : "My Name is John Smith.I am learning MongoDB database"
}
{
"_id" : ObjectId("5e4187d7f4cebbeaebec5147"),
"Paragraph" : "David Miller is a good student and learning Spring and Hibernate Framework."
} MongoDB में किसी फ़ील्ड से लौटाए गए वर्णों की मात्रा को सीमित करने के लिए क्वेरी निम्नलिखित है -
> db.demo233.aggregate(
... [
... {
... $project:
... {
... Paragraph: { $substr: [ "$Paragraph", 0, 10] }
...
... }
...} ] ) यह निम्नलिखित आउटपुट देगा -
{ "_id" : ObjectId("5e41877df4cebbeaebec5146"), "Paragraph" : "My Name is" }
{ "_id" : ObjectId("5e4187d7f4cebbeaebec5147"), "Paragraph" : "David Mill" }