| |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
-> 大数据 -> Cp3 Creating and Manipulating Documents -> 正文阅读 |
|
[大数据]Cp3 Creating and Manipulating Documents |
Inserting New Documents? Learn Data Modeling? ?How does the value fo _id get assigned to a document.it is automatically generated as an ObjectId type value. You can select a non ObjectId type value when inserting a new document, as long as that value is unique to this collection. Inserting New Documents - insert() and errors In this lesson we used the following commands: mongoimport --uri="mongodb+srv://<username>:<password>@<cluster>.mongodb.net/sample_supplies" sales.json mongoimport --uri="mongodb+srv://m001-student:m001-mongodb-basics@Sandbox.mongodb.net/sample_supplies" sales.json Step one : Connect to the Atlas cluster mongo "mongodb+srv://<username>:<password>@<cluster>.mongodb.net/admin" Step two: navigate to the database that we need: use sample_training Step three, get a random document from the collection: db.inspections.findOne(); Step four, copy this random document, and try to insert in into the collection: 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() ------------------------------------------------------------------------------------------------- ep:? C:\Users\psmax>mongosh "mongodb+srv://sandbox.gnors.mongodb.net/myFirstDatabase" --apiVersion 1 --username m001-student For mongosh info see: https://docs.mongodb.com/mongodb-shell/ Warning: Found ~/.mongorc.js, but not ~/.mongoshrc.js. ~/.mongorc.js will not be loaded. Atlas atlas-nxi8gd-shard-0 [primary] myFirstDatabase> use sample_training Atlas atlas-nxi8gd-shard-0 [primary] sample_training> db.inspections.findOne() 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() ? ? Select all true statements from the following list: MongoDB can store duplicate documents in the same collection,as long as their _id values are different. If a document is inserted without a provided _id value,then the _id field and value will be automatically generated for the inserted document before insertion. Inserting New Documents - insert() orderInsert three test documents: db.inspections.insert([ { "test": 1 }, { "test": 2 }, { "test": 3 } ]) db.inspections.insert([{ "_id": 1, "test": 1 },{ "_id": 1, "test": 2 }, { "_id": 3, "test": 3 }]) Find the documents with?_id: 1 db.inspections.find({ "_id": 1 }) Insert multiple documents specifying the?_id?values, and using the?"ordered": false?option. db.inspections.insert([{ "_id": 1, "test": 1 },{ "_id": 1, "test": 2 }, { "_id": 3, "test": 3 }],{ "ordered": false }) Insert multiple documents with?_id: 1?with the default?"ordered": true?setting db.inspection.insert([{ "_id": 1, "test": 1 },{ "_id": 3, "test": 3 }]) View?collections?in the active?db show collections Switch the active?db?to?training use training View all available databases show dbs Atlas atlas-nxi8gd-shard-0 [primary] training> db.pets.insert([{ "pet": "cat" }, { "pet": "dog" }, { "pet": "fish" }]) |
|
|
上一篇文章 下一篇文章 查看所有文章 |
|
开发:
C++知识库
Java知识库
JavaScript
Python
PHP知识库
人工智能
区块链
大数据
移动开发
嵌入式
开发工具
数据结构与算法
开发测试
游戏开发
网络协议
系统运维
教程: HTML教程 CSS教程 JavaScript教程 Go语言教程 JQuery教程 VUE教程 VUE3教程 Bootstrap教程 SQL数据库教程 C语言教程 C++教程 Java教程 Python教程 Python3教程 C#教程 数码: 电脑 笔记本 显卡 显示器 固态硬盘 硬盘 耳机 手机 iphone vivo oppo 小米 华为 单反 装机 图拉丁 |
360图书馆 购物 三丰科技 阅读网 日历 万年历 2024年11日历 | -2024/11/24 4:21:59- |
|
网站联系: qq:121756557 email:121756557@qq.com IT数码 |