-
MongoDB Array में Element Remove करना
Element remove करने के लिए update में $pull का उपयोग करें। $pull operator existing array से उन सभी instances को remove करता है जो specified condition से match करते हैं। Collection बनाना db.demo541.insertOne({software:{services:[gmail,facebook,yahoo]}}); { acknowledged : true, insertedId : ObjectId(
-
MongoDB में Array में Specific Value होने पर Boolean Field Add करना
इसके लिए $ifNull का उपयोग करें। यह expression evaluate करता है और expression का value return करता है यदि expression non-null value evaluate करता है। Collection बनाना > db.demo542.insertOne({ListOfName:[Chris,David]}); { acknowledged : true, insertedId : ObjectId(5e8cabc6ef4dcbee04fbbc17) } >
-
MongoDB में Same Array Elements वाले Document Find करना
Same array elements वाले document को find करने के लिए find() में $all का उपयोग करें। $all operator उन documents को select करता है जहां field का value एक array है जिसमें सभी specified elements मौजूद हैं। Collection बनाना > db.demo543.insertOne({id:101, subject:[MySQL, Java ,C,Python]}); { acknowl
-
MongoDB में Hour द्वारा Aggregate और $avg करना
Aggregate करने के लिए MongoDB में aggregate() का उपयोग करें। यह collection में data के aggregate values calculate करता है। Collection बनाना > db.demo544.insertOne({DueTime:new ISODate(2020-01-10 12:10:20),Amount:100}); { acknowledged : true, insertedId : ObjectId(5e8e1f029e5f92834d7f05ce) } >
-
MongoDB में NumberLong Value Print करना
Mongo shell 64-bit integers को handle करने के लिए NumberLong() wrapper provide करता है। Custom variable का उपयोग करके syntax और toString() से print करना: var anyVariableName=NumberLong(yourLongNumber); yourVariableName.toString(); उदाहरण 1 > var number=NumberLong(231231231231121231); > number
-
MongoDB Aggregate में $match और $project Implement करना
$match documents को filter करके केवल matching documents को next pipeline stage में pass करता है। $project requested fields के साथ documents को pipeline के next stage में pass करता है। Collection बनाना > db.demo545.insert({Name:Chris,details:{SubjectScore1:56,SubjectScore2:56}}) WriteResult({ nIn
-
MongoDB Aggregate में $redact का उपयोग करना
$redact documents के contents को documents themselves में stored information के आधार पर restrict करता है। Aggregate में $cond के साथ $redact का उपयोग कर सकते हैं। Collection बनाना > db.demo546.insertOne({Value1:10,Value2:20}); { acknowledged : true, insertedId : ObjectId(5e8e263f9e5f92834d7f05d7
-
MongoDB में Sub Collection के साथ Concurrent Update
Update के लिए simply update() का उपयोग करें। Sub collection तक पहुँचने और update करने के लिए $push operator के साथ dot notation का उपयोग करें। Collection बनाना > db.demo547.insertOne( ... { ... Name : Chris, ... Test : ... { ... FirstTest : ... { ... Scores: [56,29,76] ...
-
MongoDB में कुछ Documents Skip करना
हाँ, आप MongoDB में skip() का उपयोग करके कुछ documents skip कर सकते हैं। limit() का उपयोग करके display करने वाले documents की संख्या specify करें। Collection बनाना > db.demo682.insertOne({FirstName:John}); { acknowledged : true, insertedId : ObjectId(5ea462a804263e90dac94402) } > db.demo682.i
-
MongoDB में Collection में Documents की Number Limit करना
Collection में documents की number limit करने के लिए capped: true set करें। Size भी वहीँ set करें। Capped Collection बनाना > db.createCollection( demo683, { capped: true, size: 5 ,max:4} ) { ok : 1 } > db.demo683.insertOne({Value:100}); { acknowledged : true, insertedId : ObjectId(5ea468afa7e
-
MongoDB Console में Special Characters वाले Database Name का उपयोग करना
हाँ, getSiblingDB() का उपयोग करें। आइए database में कुछ documents add करते हैं: > use customer_tracker-990; switched to db customer_tracker-990 > db.demo1.insertOne({Name:Chris}); { acknowledged : true, insertedId : ObjectId(5ea4697ca7e81adc6a0b3954) } > db.demo1.insertOne({Name:David}); {
-
MongoDB Query - Roles के आधार पर केवल Name Field Fetch करना
इसके लिए aggregate() का उपयोग करें। यहाँ हमने 3 roles consider किए हैं - Admin, Guest, और User। Collection बनाना > db.demo532.insertOne({Name:Chris,Type:Admin}); { acknowledged : true, insertedId : ObjectId(5e8b4a9def4dcbee04fbbbf9) } > db.demo532.insertOne({Name:David,Type:Guest}); { acknowl
-
MongoDB में $addToSet Implement करके Single Field के Values Fetch करना
$addToSet operator value को array में add करता है जब तक value पहले से present न हो, उस case में $addToSet उस array के लिए कुछ नहीं करता। Collection बनाना > db.demo533.insertOne({ProjectName:Online Hospital Management}); { acknowledged : true, insertedId : ObjectId(5e8b4cfaef4dcbee04fbbbfc) } >
-
MongoDB में Structured Grouping Query - Count के साथ New Field Display करना
इसके लिए MongoDB में aggregate() के अंदर $group का उपयोग करें। $group input documents को specified _id expression द्वारा group करता है और प्रत्येक distinct grouping के लिए एक document output करता है। Collection बनाना > db.demo534.insertOne({_id:10,ProductId:100,ProductName:Product-1}); { acknowl
-
MongoDB में Document से Array Value Delete करना
Array values delete करने के लिए MongoDB में $pull का उपयोग करें। $pull operator existing array से उन सभी instances को remove करता है जो specified condition से match करते हैं। Collection बनाना > db.demo535.insertOne( ... { ... studentId : 101, ... studentName : Chris, ... ListOfMailIds : [
-
MongoDB में Multiple Fields के साथ Group करके Duplicate Values Count करना
इसके लिए MongoDB aggregate में $cond का उपयोग करें। $cond boolean expression को evaluate करके दो specified return expressions में से एक return करता है। Collection बनाना > db.demo536.insertOne({Name1:Chris,Name2:David}); { acknowledged : true, insertedId : ObjectId(5e8c843eef4dcbee04fbbc01) } >
-
MongoDB में Sub-documents पर Find Query Execute करना
Sub-documents के लिए dot notation का उपयोग करें। आइए पहले documents के साथ एक collection बनाते हैं: > db.demo537.insertOne({details:{SubjectName:MongoDB}}); { acknowledged : true, insertedId : ObjectId(5e8c8a10ef4dcbee04fbbc05) } > db.demo537.insertOne({details:{SubjectName:MySQL}}); { acknowl
-
MongoDB में Subdocument को Document से Remove करना
Document से subdocument remove करने के लिए $pull operator का उपयोग update() के साथ करें। आइए पहले documents के साथ एक collection बनाते हैं: > db.demo538.insertOne( ... { ... id:101, ... details : ... { ... anotherDetails: ... [ ... { ... Name:Chris, ... Age:21
-
MongoDB में Array Elements के साथ Specific Document Fetch करना
MongoDB में किसी specific document को fetch करने के लिए find() मेथड में dot notation का उपयोग करें। आइए documents के साथ एक collection बनाते हैं: > db.demo672.insertOne({Brand:[{CategoryName:Mobile,Name:Oppo}]}); { acknowledged : true, insertedId : ObjectId(5ea3ea9b04263e90dac943e5) } > db.dem
-
MongoDB db.<collectionname>.stats() के आउटपुट में max फ़ील्ड का क्या अर्थ है?
संग्रह में दस्तावेज़ों की संख्या सीमित करने के लिए max फ़ील्ड का उपयोग करें। कैप्ड संग्रह में max फ़ील्ड का उपयोग करने की क्वेरी: > db.createCollection(demo673, { capped : true, size : 100, max :50 } ) { ok : 1 } आइए दस्तावेज़ों के साथ एक संग्रह बनाएं: > db.demo673.insertOne({Name:John,Age:23}