MongoDB Basics: Chapter 3: Creating and Manipulating Documents - Inserting New Documents: insert() and errors


No Action
1
MongoDB Basics: Chapter 3: Creating and Manipulating Documents - Inserting New Documents: insert() and errors

0 comment

20 December 2020, 9:05 am by antelove19

MongoDB Basics: Chapter 3: Creating and Manipulating Documents - Inserting New Documents: insert() and errors
MongoDB Basics: Chapter 3: Creating and Manipulating Documents - Inserting New Documents: insert() and errors

In this lesson we used the following commands: ```javascript mongoimport --uri="mongodb+srv://:@.mongodb.net/sample_supplies" sales.json ```
Step one: Connect to the Atlas cluster ```javascript mongo "mongodb+srv://:@.mongodb.net/admin" ```
Step two: navigate to the database that we need: ```javascript use sample_training ```
Step three, get a random document from the collection: ```javascript db.inspections.findOne(); ```
Step four, copy this random document, and try to insert in into the collection: ```javascript db.inspections.insert({ "_id" : ObjectId("56d61033a378eccde8a8354f"), "id" : "10021-2015-ENFO", "certificate_number" : 9278806, "business_name" : "ATLIXCO DELI GROCERY INC.", "date" : "Feb 20 2015", "result" : "No Violation Issued", "sector" : "Cigarette Retail Dealer - 127", "address" : { "city" : "RIDGEWOOD", "zip" : 11385, "street" : "MENAHAN ST", "number" : 1712 } }) db.inspections.insert({ "id" : "10021-2015-ENFO", "certificate_number" : 9278806, "business_name" : "ATLIXCO DELI GROCERY INC.", "date" : "Feb 20 2015", "result" : "No Violation Issued", "sector" : "Cigarette Retail Dealer - 127", "address" : { "city" : "RIDGEWOOD", "zip" : 11385, "street" : "MENAHAN ST", "number" : 1712 } }) db.inspections.find({"id" : "10021-2015-ENFO", "certificate_number" : 9278806}).pretty() ```

Keywords:



Sources:

  1. university.mongodb.com