// 4/16/25 use tinker db.test1.insertOne( { "StudentId" :1, "StudentName" : "Joseph Connor" } ) doc1 = { "StudentId" :1, "StudentName" : "Joseph Connor" } doc1 db.test1.insertOne(doc1) db.test1.find() if (db.test1.find(doc1).count() == 0) { db.test1.insertOne(doc1) } show dbs db.dropDatabase() show dbs // remove tinker use tinker db.test1.find() doc = { "StudentId" :1, "StudentName" : "Joseph Connor" } doc if (db.test1.find(doc).count() == 0) { db.test1.insertOne(doc) } db.test1.find() if (db.test1.find(doc).count() == 0) { db.test1.insertOne(doc) } db.test1.find() 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" } } ]) db.test1.find() mongorestore --archive="toyu-db.gz" --gzip --nsFrom='toyu.*' --nsTo='toyu.*' //Show all students. use toyu db.student.find() db.student.find({}, { "_id": 0 } ) db.student.find({}, { "_id": false } ) db.student.find({"major": "CINF"}, { "_id": 0, "stuId": 1, "fname": 1, "lname": 1, "major": 1 } ) db.student.find({"maj": "CINF"}, { "_id": 0, "stuId": 1, "fname": 1, "lname": 1, "major": 1 } ) // Show all student names. Return an array of student objects. db.student.find({}, { "fname": 1, "lname":1, "_id": 0 } ) result = db.student.find({}, { "fname": 1, "lname":1, "_id": 0 } ).toArray() // May not always work as toArray() returns a promise, // which may not be ready for use. result.forEach((x,i) => console.log('student #' + String(i) + ': ' + x["fname"] + ' ' + x["lname"])) result.forEach((x,i) => console.log('student #' + String(i+1) + ': ' + x["fname"] + ' ' + x["lname"])) // Show the names and credits (ach) of students majoring in 'CSCI' and having 40 or more credits. db.student.find( { "major": "CSCI", "ach" : {$gte: 40} }, { "fname": 1, "lname":1, "ach":1, "_id": 0 } ) db.student.find( { "major": "CSCI", "ach" : {$gte: 40} }, { "fname": 1, "lname":1, "ach":1, "major":1, "_id": 0 } )