C:\S2025_JointDB\website\demo\d5333>mongosh Current Mongosh Log ID: 67feb70e21ac55e0f981460e Connecting to: mongodb://127.0.0.1:27017/?directConnection=true&serverSelectionTimeoutMS=2000 Using MongoDB: 5.0.5 Using Mongosh: 1.1.8 For mongosh info see: https://docs.mongodb.com/mongodb-shell/ ------ The server generated these startup warnings when booting: 2025-03-26T11:22:34.617-05:00: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted ------ test> use tinker switched to db tinker tinker> db.test1.insertOne( ... { ..... "StudentId" :1, ..... "StudentName" : "Joseph Connor" ..... } ... ) Browserslist: caniuse-lite is outdated. Please run: npx browserslist@latest --update-db Why you should do it regularly: https://github.com/browserslist/browserslist#browsers-data-updating { acknowledged: true, insertedId: ObjectId("67feba7a4d829c4cecc30f1c") } tinker> db.test1.find() [ { _id: ObjectId("67feba7a4d829c4cecc30f1c"), StudentId: 1, StudentName: 'Joseph Connor' } ] tinker> db.test1.insertOne [Function: insertOne] AsyncFunction { apiVersions: [ 1, Infinity ], serverVersions: [ '3.2.0', '999.999.999' ], returnsPromise: true, topologies: [ 'ReplSet', 'Sharded', 'LoadBalanced', 'Standalone' ], returnType: { type: 'unknown', attributes: {} }, deprecated: false, platforms: [ 0, 1, 2 ], isDirectShellCommand: false, acceptsRawInput: false, shellCommandCompleter: undefined, help: [Function (anonymous)] Help } tinker> db.test1.insertOne( ... { ..... "StudentId" :1, ..... "StudentName" : "Joseph Connor" ..... } ... ) { acknowledged: true, insertedId: ObjectId("67febdc04d829c4cecc30f1d") } tinker> db.test1.find() [ { _id: ObjectId("67feba7a4d829c4cecc30f1c"), StudentId: 1, StudentName: 'Joseph Connor' }, { _id: ObjectId("67febdc04d829c4cecc30f1d"), StudentId: 1, StudentName: 'Joseph Connor' } ] tinker> use tinker already on db tinker tinker> doc = { ... "StudentId" :1, ... "StudentName" : "Joseph Connor" ... } { StudentId: 1, StudentName: 'Joseph Connor' } tinker> doc { StudentId: 1, StudentName: 'Joseph Connor' } tinker> db.test1.insertOne(doc) { acknowledged: true, insertedId: ObjectId("67febf554d829c4cecc30f1e") } tinker> db.test1.find() [ { _id: ObjectId("67febf554d829c4cecc30f1e"), StudentId: 1, StudentName: 'Joseph Connor' } ] tinker> if (db.test1.find(doc).count() == 0) { db.test1.insertOne(doc) } tinker> doc2 = { ... "StudentId" :5, ... "StudentName" : "Mary Connor" ... } { StudentId: 5, StudentName: 'Mary Connor' } tinker> doc2 { StudentId: 5, StudentName: 'Mary Connor' } tinker> if (db.test1.find(doc2).count() == 0) { db.test1.insertOne(doc2) } { acknowledged: true, insertedId: ObjectId("67fec01b4d829c4cecc30f1f") } tinker> if (db.test1.find(doc2).count() == 0) { db.test1.insertOne(doc2) } tinker> tinker> tinker> // remove tinker tinker> show dbs MMIM_Ex2 205 kB RefInt 123 kB admin 135 kB config 111 kB local 115 kB swim 532 kB tinker 73.7 kB toyu 369 kB tinker> db.dropDatabase() { ok: 1, dropped: 'tinker' } tinker> show dbs MMIM_Ex2 205 kB RefInt 123 kB admin 135 kB config 111 kB local 115 kB swim 532 kB toyu 369 kB tinker> // create index tinker> db.test1.createIndex( { "StudentId": 1 }, { unique: true } ) StudentId_1 tinker> doc = { ... "StudentId" :1, ... "StudentName" : "Joseph Connor" ... } { StudentId: 1, StudentName: 'Joseph Connor' } tinker> doc { StudentId: 1, StudentName: 'Joseph Connor' } tinker> db.test1.insertOne(doc) { acknowledged: true, insertedId: ObjectId("67fec18f4d829c4cecc30f20") } tinker> db.test1.insertOne(doc) MongoServerError: E11000 duplicate key error collection: tinker.test1 index: StudentId_1 dup key: { StudentId: 1 } tinker> db.test1.insertMany([ ... { "StudentId" :2, ..... "GPA": 3.72 ..... }, ... { "StudentId" :3, ..... "GPA": 1.69 ..... }, ... { ..... "BCAssetId": "78c22fc6-5dec-11ec-bf63-0242ac130002", ..... "BCAssetType": "BCAssetTypeMetadata", ..... "BCAssetName": "BCAssetTypeMetadata: MBSEModel", ..... "ForBCAssetType": "MBSEModel", ..... "Version": { ....... "Version": "1.0", ....... "Subversion": null, ....... "StartTime": "2019-01-13T07:23:13+06:00" ....... } ..... } ... ]) { acknowledged: true, insertedIds: { '0': ObjectId("67fec2104d829c4cecc30f22"), '1': ObjectId("67fec2104d829c4cecc30f23"), '2': ObjectId("67fec2104d829c4cecc30f24") } } tinker> db.test1.find() [ { _id: ObjectId("67fec18f4d829c4cecc30f20"), StudentId: 1, StudentName: 'Joseph Connor' }, { _id: ObjectId("67fec2104d829c4cecc30f22"), StudentId: 2, GPA: 3.72 }, { _id: ObjectId("67fec2104d829c4cecc30f23"), StudentId: 3, GPA: 1.69 }, { _id: ObjectId("67fec2104d829c4cecc30f24"), BCAssetId: '78c22fc6-5dec-11ec-bf63-0242ac130002', BCAssetType: 'BCAssetTypeMetadata', BCAssetName: 'BCAssetTypeMetadata: MBSEModel', ForBCAssetType: 'MBSEModel', Version: { Version: '1.0', Subversion: null, StartTime: '2019-01-13T07:23:13+06:00' } } ] tinker> tinker> use toyu switched to db toyu toyu> db.student.find() [ { _id: ObjectId("63c19f66c1fb90601512c759"), stuId: 100000, fname: 'Tony', lname: 'Hawk', major: 'CSCI', minor: 'CINF', ach: 40, advisor: 1011 }, { _id: ObjectId("63c19f66c1fb90601512c75a"), stuId: 100001, fname: 'Mary', lname: 'Hawk', major: 'CSCI', minor: 'CINF', ach: 35, advisor: 1011 }, { _id: ObjectId("63c19f66c1fb90601512c75b"), stuId: 100002, fname: 'David', lname: 'Hawk', major: 'CSCI', minor: 'ITEC', ach: 66, advisor: 1012 }, { _id: ObjectId("63c19f66c1fb90601512c75c"), stuId: 100003, fname: 'Catherine', lname: 'Lim', major: 'ITEC', minor: 'CINF', ach: 20, advisor: null }, { _id: ObjectId("63c19f66c1fb90601512c75d"), stuId: 100004, fname: 'Larry', lname: 'Johnson', major: 'ITEC', minor: null, ach: 66, advisor: 1017 }, { _id: ObjectId("63c19f66c1fb90601512c75e"), stuId: 100005, fname: 'Linda', lname: 'Johnson', major: 'CINF', minor: 'ENGL', ach: 13, advisor: 1015 }, { _id: ObjectId("63c19f66c1fb90601512c75f"), stuId: 100006, fname: 'Lillian', lname: 'Johnson', major: 'CINF', minor: 'ITEC', ach: 18, advisor: 1016 }, { _id: ObjectId("63c19f66c1fb90601512c760"), stuId: 100007, fname: 'Ben', lname: 'Zico', major: null, minor: null, ach: 16, advisor: null }, { _id: ObjectId("63c19f66c1fb90601512c761"), stuId: 100008, fname: 'Bill', lname: 'Ching', major: 'ARTS', minor: null, ach: 90, advisor: null }, { _id: ObjectId("63c19f66c1fb90601512c762"), stuId: 100009, fname: 'Linda', lname: 'King', major: 'ARTS', minor: 'CSCI', ach: 125, advisor: 1018 }, { _id: ObjectId("63c19f66c1fb90601512c763"), stuId: 100111, fname: 'Cathy', lname: 'Johanson', major: null, minor: null, ach: 0, advisor: 1018 } ] toyu> // Show all information of students majoring in 'CINF'. toyu> toyu> db.student.find({"major": "CINF"}, ... { "_id": 0 } ... ) [ { stuId: 100005, fname: 'Linda', lname: 'Johnson', major: 'CINF', minor: 'ENGL', ach: 13, advisor: 1015 }, { stuId: 100006, fname: 'Lillian', lname: 'Johnson', major: 'CINF', minor: 'ITEC', ach: 18, advisor: 1016 } ] toyu> toyu> db.student.find({"major": "CINF"}, ... { "_id": false } ... ) [ { stuId: 100005, fname: 'Linda', lname: 'Johnson', major: 'CINF', minor: 'ENGL', ach: 13, advisor: 1015 }, { stuId: 100006, fname: 'Lillian', lname: 'Johnson', major: 'CINF', minor: 'ITEC', ach: 18, advisor: 1016 } ] toyu> // Show all student names. Return an array of student objects. toyu> db.student.find({}, ... { "fname": 1, "lname":1, "_id": 0 } ... ) [ { fname: 'Tony', lname: 'Hawk' }, { fname: 'Mary', lname: 'Hawk' }, { fname: 'David', lname: 'Hawk' }, { fname: 'Catherine', lname: 'Lim' }, { fname: 'Larry', lname: 'Johnson' }, { fname: 'Linda', lname: 'Johnson' }, { fname: 'Lillian', lname: 'Johnson' }, { fname: 'Ben', lname: 'Zico' }, { fname: 'Bill', lname: 'Ching' }, { fname: 'Linda', lname: 'King' }, { fname: 'Cathy', lname: 'Johanson' } ] toyu> result = db.student.find({}, ... { "fname": 1, "lname":1, "_id": 0 } ... ).toArray() [ { fname: 'Tony', lname: 'Hawk' }, { fname: 'Mary', lname: 'Hawk' }, { fname: 'David', lname: 'Hawk' }, { fname: 'Catherine', lname: 'Lim' }, { fname: 'Larry', lname: 'Johnson' }, { fname: 'Linda', lname: 'Johnson' }, { fname: 'Lillian', lname: 'Johnson' }, { fname: 'Ben', lname: 'Zico' }, { fname: 'Bill', lname: 'Ching' }, { fname: 'Linda', lname: 'King' }, { fname: 'Cathy', lname: 'Johanson' } ] toyu> toyu> // May not always work as toArray() returns a promise, toyu> // which may not be ready for use. toyu> result.forEach((x,i) => console.log('student #' + String(i) + ': ' + x["fname"] + ' ' + x["lname"])) student #0: Tony Hawk student #1: Mary Hawk student #2: David Hawk student #3: Catherine Lim student #4: Larry Johnson student #5: Linda Johnson student #6: Lillian Johnson student #7: Ben Zico student #8: Bill Ching student #9: Linda King student #10: Cathy Johanson toyu>