MongoDB :is a NoSQL database. It stores data in atype of JSON fromat called BSON. A database :is collection of data stored in format that can easily be accessed. SQL DATABASE NOSQL DATABASE here is save data in table format here is save data in json (documnet)format is called collection ==> datatype JSON BSON(Binary) String string ,Double,32,64 bit integer,boolean,array,expression,timetamp, number date,objectid Boolean expression,timetamp,date,objectid Array object null ==> diffrent text-based(human-readable) Binary(not human-readable) large dut to text more compact slower speed faste speed web API & data exchange MongoDB and database storage with a rich set of data types =>>MongoDB Benifit flexible schema design Horizontal scalabilty through sjarding. High perfomance for head and write operations powerful query lanuage Bulid-in replication for high availability geospatial data support json like analytics capability easy integration with big data tools Opern-source and commmuniity-driven installation MongoDB commmuniity Server (install c drive inside program ) MongoDB Shell (mongosh) (install in c with create new folder) .DB path setting go program folder find MongoDB inside copypath C:\Program Files\MongoDB\Server\8.0\bin then go pc search edit the syteam enviroment click enviroment variable and click sytem variable and click in path click new and paste path url here C:\Program Files\MongoDB\Server\8.0\bin ok ok o k ok 2.shell path setting go c drive mongosh folder copy path and open pc edit the syteam enviroment click user variable and click path and click new and paste mongosh path url ok ok ok okk NOW CMD open OR use mongosh shell(go folder click mongosh) then press enter for connect type mongosh (checking install successfull or not) show dbs (check data base) ctrl+l =all clear screen CMD =>>> @@@@@@@@@@@@@@@@@@@ SOME COMMAND @@@@@@@@@@@@@@@@@@ CREATE DATABASE AND collection(table sql) (data or record is called document) 2.use database_name (for create database ) eg use rupeshmonDB 3.db.createCollection("collection_name") eg db.createCollection("rupeshmonDB_Collec") 4.db which data you are using 5.show dbs (check database) 6 show collections (collection(table data documnet)) 7.db.rupeshmonDB_Collec.renameCollection("studenttb") renme collections name db.help db.studenttb.help() 8.db.studenttb.drop() collections drop 9. use database_name db.dropDatabase() using database delete =>> @@@@@@@@@@@@@@@@@@@ INSERT COMMAND @@@@@@@@@@@@@@@@@@ Two type 1.insertOne 2.insertMany syntax 2.db.collection_name.insertOne({"field1":"Value"field2:Value,}) eg db.studenttb.insertOne({"name":"ram",age:25,class:"BCA"}) 3.db.collection_name.insertMany[ {"field1":"Value"field2:Value }, {"field3":"Value"field4:Value }, ] eg db.studenttb.insertMany([{"name":"aniaa",age:3,class:"Bodh"},{"name":"manish",age:4,class:"lion"}]) 4.db.studenttb.find() show collection record eg [ { _id: ObjectId('67ee16243ba2ff1164b71236'), name: 'ram', age: 25, class: 'BCA' } ] =>>>>@@@@@@@@@@@@@@@@@ MONGOdb DATA types string Double =>it mena float value like 88.88 32 bit integer, 64 bit integer, boolean, array, Regular expression not used ,timetamp, date, dob:ISODate("2000- 10- 15T08:00:00Z") objectid 2.DATE DATA TYPES { dob:ISODate("2024- 10- 18T18:30:00Z")} T=Time z=UTC(coordinated Universal Time) if add 2 hour { dob:ISODate("2024- 10- 18T18:30:00+2:00")} ( Central European time) if - 5 hour { dob:ISODate("2024- 10- 18T18:30:00-5:00")} (Eastern standard Time) { dob:ISODate("2024- 10- 18T18:30:00")} (local Time Zone) or {dob:new Date("2024- 10- 18T10:30:00Z)} {dob:new Date()} =>this for current date time 3. 32 bit integer => Has a minimum value of -2,147,483,648 and a maximum value of 2,147,483,647 Is represented in twos complement notation ,The first bit is the signing bit use 4 bytes of memory to store the integer value 64 bit integer, -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807. =>use 8 bytes of memory to store the integer value ====== lab:==== db.personal.insertOne({ name:"rupehtech", age:25, married:false, dob: ISODate("2000-10-15T08:00:00Z"), wight:72.50, kids:null, hobies:["music","hek", "kiloo"], address: { "street":"123 main st", "city":"delhi", "zip":10001 } }) ==> for seeing db.personal.find() [ { _id: ObjectId('67efb7970b8baa1316b71236'), name: 'rupehtech', age: 25, married: false, dob: ISODate('2000-10-15T08:00:00.000Z'), wight: 72.5, kids: null, hobies: [ 'music', 'hek', 'kiloo' ], address: { street: '123 main st', city: 'delhi', zip: 10001 } } ] ====>2 JSON SCEMA VALIDATION =====> JO DATATYPE HAI USME WAHI DATA AAE JO DATA TYPE HAI .............EXAMPLE AGE ME INTIGER VALUE HONA CHAHIE KOI DATA TYPE NAHI ESKE LIE JSON schema VALIDATION USE KRTE HAI TAKI DATA TYPE HAI KA VALIDATION HO SKE db.createCollection("student,{ validator:{ $jsonSchema:{ required:["name","age"],title:"Studnet object validation", properties:{ age:{ bsontype:"int", minimum:5, maximum:20, description:"Age must be an integer betwwen 5 and 20 " } }, } } }); ==>@@ bsonType : validator "string", enum double minimum maximum integer(int) minimum maximum array items{bsonType:"string"} object date ===>@@ object validation address:{ bsonType:"object", required:["street","city","zip"], properties:{ street:{ bsonType:"string", description:"hello streent must be a string and is required" }, city:{ bsonType:"string", description:"city must be a string and is required" }, zipcode:{ bsonType:"int", description:"zip code must be a string and is required." } } } ==>@@@@@@ validate collections example db.createCollection("Vstudent",{ validator: { $jsonSchema:{ title:"Vstudent object validatation" , required:["name", "age", "course"], properties:{ name:{ bsonType:"string", description:"Name must be string and is required."}, age:{ bsonType:"int", minimum:5, maximum:20, description:"age must be integer and is required."}, course:{ bsonType: "string", enum: ["BCA", "BTECH", "bsc"], description: "Course must be following this value." }, } } } }); ==>@@@@ validate collections inside insert data @apply write data db.Vstudent.insertOne({ name: "RUPESHTECH", age: 20, course: "BCA" }) @apply wrong data db.Vstudent.insertOne({ name: 65, age: 20, course: "BCA" }) @apply wrong data db.Vstudent.insertOne({ name: "65", age: 5, course: "bsc" }) for see data db.Vstudent.find() ==>@@@@@ MODIFY EXISTING COLLECTION schema db.runCommand({ collMod:"personal", validator:{ $jsonSchema:{ required:["name","age","married","dob","weight","kids","hobies","address"], properties:{ name:{ bsonType:"string", description:"Name must be a string and is required" }, age:{ bsonType:"int", minimum:8, maximum:25, description:"age must be a int and 8 betwwen 25 is required" }, married:{ bsonType:"bool", description:"married must be a boolean and is required" }, dob:{ bsonType:"date", description:"dob must be a date and is required" }, weight:{ bsonType:"double", description:"weight must be a double and is required" }, kids:{ bsonType:"int", description:"kids must be a int and is required" }, hobies:{ bsonType:"array", items:{ bsonType:"string" }, description:"hobies must be a array and is required" }, address:{ bsonType:"object", required:["street","city","zip"], properties:{ street:{ bsonType:"string", description:"street must be a string " }, city:{ bsonType:"string", description:"city must be a string " }, zip:{ bsonType:"int", description:"zip must be a int " } } } } } } });
June-06-2025 21:23:08
June-06-2025 11:35:05
June-06-2025 08:25:42
June-02-2025 21:09:41
June-02-2025 10:56:22
June-02-2025 10:27:58
June-02-2025 10:15:40
May-30-2025 19:20:40
May-30-2025 19:14:29
May-27-2025 21:52:18
May-27-2025 21:33:30
May-26-2025 17:11:41
May-26-2025 16:53:29
May-26-2025 16:50:59
May-13-2025 21:02:32
May-13-2025 17:46:23
May-12-2025 15:41:29