找到 1660 篇文章,关于大数据分析
118 次浏览
要访问子文档值,让我们首先创建一个包含文档的集合 −> db.accessSubDocumentDemo.insertOne( ... { ... ... "Details" : { ... "1" : { ... "StudentLowerScore" : "33", ... "StudentHoghScore" : "55" ... }, ... "2" : { ... "StudentLowerScore" : "45", ... "StudentHoghScore" : "65" ... }, ... "3" : ... 阅读更多
182 次浏览
您可以使用 $pull 运算符。让我们首先创建一个包含文档的集合 −> db.pullAnArrayElementDemo.insertOne( { "StudentDetails": [ { "StudentFirstName":"Chris", "StudentScore":56 }, {"StudentFirstName":"Robert", "StudentScore":59 } ] } ); { "acknowledged" : true, "insertedId" : ObjectId("5cd3b55bedc6604c74817cd5") }以下是使用 find() 方法显示集合中所有文档的查询 −> db.pullAnArrayElementDemo.find().pretty();这将产生以下输出 −{ "_id" : ObjectId("5cd3b55bedc6604c74817cd5"), "StudentDetails" : [ { "StudentFirstName" : "Chris", "StudentScore" : 56 }, { ... 阅读更多
464 次浏览
您可以在 aggregate() 下使用 $match 运算符来获取第一条记录。让我们首先创建一个包含文档的集合 −> db.conditionalFirstDemo.insertOne({_id:100, "StudentName":"Chris", "StudentSubject":null}); { "acknowledged" : true, "insertedId" : 100 } > db.conditionalFirstDemo.insertOne({_id:101, "StudentName":"Chris", "StudentSubject":null}); { "acknowledged" : true, "insertedId" : 101 } >db.conditionalFirstDemo.insertOne({_id:102, "StudentName":"Chris", "StudentSubject":"MongoDB"}); { "acknowledged" : true, "insertedId" : 102 } >db.conditionalFirstDemo.insertOne({_id:103, "StudentName":"Chris", "StudentSubject":"MongoDB"}); { "acknowledged" : true, "insertedId" : 103 } > db.conditionalFirstDemo.insertOne({_id:104, "StudentName":"Chris", "StudentSubject":null}); { "acknowledged" : true, "insertedId" : 104 }以下是使用 find() 方法显示集合中所有文档的查询 −> db.conditionalFirstDemo.find();这将产生以下 ... 阅读更多
1K+ 次浏览
要正确创建集合,您需要在调用中使用 MongoDB 对象,即 db.createCollection("yourCollectionName");让我们实现上述语法以创建集合并使用 MongoDB 对象调用它 −> use sample; switched to db sample > db.createCollection("employeeInformation"); { "ok" : 1 }显示来自上述“sample”数据库的所有集合 −> db.getCollectionNames();这将产生以下输出 −[ "arraySizeErrorDemo", "atleastOneMatchDemo", "basicInformationDemo", "combinedAndOrDemo", "convertSQLQueryDemo", "copyThisCollectionToSampleDatabaseDemo", "countOrSizeDemo", "distinctOnMultipleFieldsDemo", "documentWithAParticularFieldValueDemo", "employee", "employeeInformation", "findListOfIdsDemo", "findMimimumElementInArrayDemo", "findSubstring", "getAllRecordsFromSourceCollectionDemo", "getElementWithMaxIdDemo", "insertDocumentWithDateDemo", "internalArraySizeDemo", ... 阅读更多
187 次浏览
让我们首先创建一个包含文档的集合 −> db.embeddedDocumentDemo.insertOne( ... { ... "CustomerDetails":[ ... {"CustomerName":"Chris", "CustomerPurchasePrice":3000}, ... {"CustomerName":"Robert", "CustomerPurchasePrice":4500}, ... {"CustomerName":"David", "CustomerPurchasePrice":1000}, ... ] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5cd32347edc6604c74817ccd") }以下是使用 find() 方法显示集合中所有文档的查询 −> db.embeddedDocumentDemo.find().pretty();这将产生以下输出 −{ "_id" : ObjectId("5cd32347edc6604c74817ccd"), "CustomerDetails" : [ { "CustomerName" ... 阅读更多
194 次浏览
让我们首先创建一个包含文档的集合 −> db.projectionAnElementDemo.insertOne( ... { ... "CustomerId":100, ... "CustomerDetails": [ ... { ... "CustomerName": "Chris", ... "CustomerCountryName": "US" ... }, ... { ... "CustomerName": "Robert", ... "CustomerCountryName": "UK" ... } ... ] ... } ... ); { "acknowledged" : true, ... 阅读更多
438 次浏览
您可以为此使用 $set 运算符。让我们首先创建一个包含文档的集合 −> db.updateSubObjectDemo.insertOne( ... { ... ... "ClientId" : 100, ... "ClientDetails" : { ... "ClientFirstName" : "Adam" ... } ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5cd31434b64f4b851c3a13e9") }以下是使用 find() 方法显示集合中所有文档的查询 −> db.updateSubObjectDemo.find().pretty();这将产生以下输出 −{ "_id" : ObjectId("5cd31434b64f4b851c3a13e9"), "ClientId" : 100, "ClientDetails" : { ... 阅读更多
116 次浏览
让我们首先创建一个包含文档的集合 −>db.replacingEntireDocumentDemo.insertOne({"StudentFirstName":"John", "StudentLastName":"Smith", "StudentCountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd3119bb64f4b851c3a13e8") }以下是使用 find() 方法显示集合中文档的查询 −> db.replacingEntireDocumentDemo.find().pretty();这将产生以下输出 −{ "_id" : ObjectId("5cd3119bb64f4b851c3a13e8"), "StudentFirstName" : "John", "StudentLastName" : "Smith", "StudentCountryName" : "US" }以下是替换整个文档时更新 MongoDB 文档的查询 −>db.replacingEntireDocumentDemo.update({"StudentFirstName":"John", "StudentLastName":"Smith", "StudentCountryName":"US"}, {"StudentFirstName":"David", "StudentLastName":"Miller", "StudentCountryName":"AUS"}); WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })让我们显示集合中的所有记录 ... 阅读更多
823 次浏览
使用 unique 并将其设置为 TRUE。让我们通过创建索引并将两列设置为唯一来实现相同的功能 −>db.keepTwoColumnsUniqueDemo.createIndex({"StudentFirstName":1, "StudentLastName":1}, {unique:true}); { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 }现在您可以在上述集合中插入文档 −>db.keepTwoColumnsUniqueDemo.insertOne({"StudentFirstName":"John", "StudentLastName":"Smith", "StudentAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5cd30fd7b64f4b851c3a13e5") } >db.keepTwoColumnsUniqueDemo.insertOne({"StudentFirstName":"John", "StudentLastName":"Doe", "StudentAge":23}); { "acknowledged" : true, "insertedId" : ObjectId("5cd30fe5b64f4b851c3a13e6") } >db.keepTwoColumnsUniqueDemo.insertOne({"StudentFirstName":"John", "StudentLastName":"Smith", "StudentAge":24}); 2019-05-08T22:50:42.803+0530 E QUERY [js] WriteError: E11000 duplicate key error collection: sample.keepTwoColumnsUniqueDemo index: StudentFirstName_1_StudentLastName_1 dup key: { : "John", : "Smith" } ... 阅读更多
482 次浏览
使用 delete 运算符在 MongoDB shell 中取消设置变量。以下是语法:
delete yourVariableName;
现在让我们实现上述语法以在 MongoDB shell 中取消设置变量。首先,打印变量名:
-> customerDetail;
这将产生以下输出:
2019-05-08T22:29:17.361+0530 E QUERY [js] ReferenceError: customerDetail is not defined : @(shell):1:1
现在,您可以在上述变量中设置值。以下是查询:
-> customerDetail={"CustomerFirstName":"Chris"};
这将产生以下输出:
{ "CustomerFirstName" : "Chris" }
以下是显示变量值的查询:
-> customerDetail;
这将产生以下输出:
{ "CustomerFirstName" : "Chris" }
以下……阅读更多