Computer >> कंप्यूटर ट्यूटोरियल >  >> प्रोग्रामिंग >> MongoDB

MongoDB में किसी विशेष कैरेक्टर से समाप्त होने वाले मानों वाले दस्तावेज़ कैसे प्राप्त करें?


MongoDB में विशेष कैरेक्टर से समाप्त होने वाले मानों वाले दस्तावेज़ प्राप्त करना

MongoDB में किसी विशेष कैरेक्टर से समाप्त होने वाले मानों वाले दस्तावेज़ प्राप्त करने का सिंटैक्स निम्नलिखित है:

db.yourCollectionName.find({yourFieldName: {$regex: "yourEndingCharacter$"}}).pretty();

उदाहरण: दस्तावेज़ों के साथ एक कलेक्शन बनाना

>db.retrieveDocumentsWithEndsWithParticularCharacterDemo.insertOne({"StudentName":"Adam","StudentAge":25,"StudentCountryName":"LAOS"}); 
{ "acknowledged" : true, "insertedId" : ObjectId("5c9c45b32d66697741252456") } 
>db.retrieveDocumentsWithEndsWithParticularCharacterDemo.insertOne({"StudentName":"Sam","StudentAge":24,"StudentCountryName":"ANGOLA"}); 
{ "acknowledged" : true, "insertedId" : ObjectId("5c9c45c02d66697741252457") } 
>db.retrieveDocumentsWithEndsWithParticularCharacterDemo.insertOne({"StudentName":"Robert","StudentAge":21,"StudentCountryName":"AUS"}); 
{ "acknowledged" : true, "insertedId" : ObjectId("5c9c45cb2d66697741252458") } 
>db.retrieveDocumentsWithEndsWithParticularCharacterDemo.insertOne({"StudentName":"Chris","StudentAge":20,"StudentCountryName":"UK"}); 
{ "acknowledged" : true, "insertedId" : ObjectId("5c9c45d92d66697741252459") } 
>db.retrieveDocumentsWithEndsWithParticularCharacterDemo.insertOne({"StudentName":"Larry","StudentAge":23,"StudentCountryName":"US"}); 
{ "acknowledged" : true, "insertedId" : ObjectId("5c9c45eb2d6669774125245a") }

find() मेथड से सभी दस्तावेज़ प्रदर्शित करना

> db.retrieveDocumentsWithEndsWithParticularCharacterDemo.find().pretty();

यह निम्नलिखित आउटपुट देगा:

{ "_id" : ObjectId("5c9c45b32d66697741252456"), "StudentName" : "Adam", "StudentAge" : 25, "StudentCountryName" : "LAOS" } 
{ "_id" : ObjectId("5c9c45c02d66697741252457"), "StudentName" : "Sam", "StudentAge" : 24, "StudentCountryName" : "ANGOLA" } 
{ "_id" : ObjectId("5c9c45cb2d66697741252458"), "StudentName" : "Robert", "StudentAge" : 21, "StudentCountryName" : "AUS" } 
{ "_id" : ObjectId("5c9c45d92d66697741252459"), "StudentName" : "Chris", "StudentAge" : 20, "StudentCountryName" : "UK" } 
{ "_id" : ObjectId("5c9c45eb2d6669774125245a"), "StudentName" : "Larry", "StudentAge" : 23, "StudentCountryName" : "US" }

"S" कैरेक्टर से समाप्त होने वाले मानों वाले दस्तावेज़ प्राप्त करने का क्वेरी

> db.retrieveDocumentsWithEndsWithParticularCharacterDemo.find({StudentCountryName: {$regex: "S$"}}).pretty();

यह निम्नलिखित आउटपुट देगा (LAOS, AUS, US - सभी "S" से समाप्त होते हैं):

{ "_id" : ObjectId("5c9c45b32d66697741252456"), "StudentName" : "Adam", "StudentAge" : 25, "StudentCountryName" : "LAOS" } 
{ "_id" : ObjectId("5c9c45cb2d66697741252458"), "StudentName" : "Robert", "StudentAge" : 21, "StudentCountryName" : "AUS" } 
{ "_id" : ObjectId("5c9c45eb2d6669774125245a"), "StudentName" : "Larry", "StudentAge" : 23, "StudentCountryName" : "US" }
  1. - MongoDB में एक क्वेरी से कई डॉक्यूमेंट्स कैसे अपडेट करें?

    एक क्वेरी से कई डॉक्यूमेंट्स अपडेट करने के लिए MongoDB में bulkWrite() का उपयोग करें। आइए एक कलेक्शन बनाते हैं: > db.demo760.insertOne({id:1,details:{Value1:100,Value2:50}}); { acknowledged : true, insertedId : ObjectId(5eb0309f5637cd592b2a4aee) } > db.demo760.insertOne({id:2,details:{Value1:

  1. - MySQL SELECT के साथ कॉलम मानों के अंत में वर्ण जोड़ना

    इसके लिए, आपको CONCAT() का उपयोग करके कन्कैटेनेशन करना होगा। पहले एक टेबल बनाते हैं: mysql> create table DemoTable766 (Name varchar(100)); Query OK, 0 rows affected (0.65 sec) इन्सर्ट कमांड का उपयोग करके टेबल में कुछ रिकॉर्ड डालें: mysql> insert into DemoTable766 values(John); Query OK, 1 row

  1. - Java का उपयोग करके MongoDB कलेक्शन से सभी डॉक्यूमेंट्स कैसे प्राप्त करें?

    आप MongoDB में मौजूदा कलेक्शन से find() मेथड का उपयोग करके डॉक्यूमेंट्स प्राप्त कर सकते हैं। सिंटैक्स db.coll.find() जहां, db डेटाबेस है। coll वह कलेक्शन (नाम) है जिससे आप डॉक्यूमेंट्स प्राप्त करना चाहते हैं। उदाहरण मान लें कि MongoDB डेटाबेस में students नामक एक कलेक्शन है जिसमें निम्नलिखित डॉक्