找到 1660 篇文章 關於大資料分析
2K+ 閱讀量
您可以使用 $regex 運算子來檢查 MongoDB 中的欄位是否包含某個字串。語法如下:db.yourCollectionName.findOne({"yourFieldName":{$regex:".*yourValue.*"}});為了理解上述概念,讓我們建立一個包含文件的集合。建立包含文件的集合的查詢如下:> db.checkFieldContainsStringDemo.insertOne({"Id":1, "Name":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5c77d762fc4e719b197a12ed") } > db.checkFieldContainsStringDemo.insertOne({"Id":2, "Name":"Johnson"}); { "acknowledged" : true, "insertedId" : ObjectId("5c77d76bfc4e719b197a12ee") } > db.checkFieldContainsStringDemo.insertOne({"Id":3, "Name":"Carol"}); { "acknowledged" : true, "insertedId" : ObjectId("5c77d774fc4e719b197a12ef") } > db.checkFieldContainsStringDemo.insertOne({"Id":4, "Name":"Mike"}); { "acknowledged" : true, "insertedId" : ObjectId("5c77d77cfc4e719b197a12f0") } > db.checkFieldContainsStringDemo.insertOne({"Id":5, "Name":"Sam"}); ... 閱讀更多
2K+ 閱讀量
要在 MongoDB 中查詢長度大於特定值的字串,請使用 $where 運算子。語法如下:db.yourCollectionName.find({$where:'this.yourStringFieldName.length > yourIntegerValue'}).pretty();為了理解上述概念,讓我們建立一個包含文件的集合。建立包含文件的集合的查詢如下:> db.stringFieldLengthDemo.insertOne({"UserId":1, "UserName":"Adam Smith"}); { "acknowledged" : true, "insertedId" : ObjectId("5c77bb4b2386c62d05142a78") } > db.stringFieldLengthDemo.insertOne({"UserId":2, "UserName":"Carol Taylor"}); { "acknowledged" : true, "insertedId" : ObjectId("5c77bb562386c62d05142a79") } > db.stringFieldLengthDemo.insertOne({"UserId":3, "UserName":"James Brown"}); { "acknowledged" : true, "insertedId" : ObjectId("5c77bb5b2386c62d05142a7a") } > db.stringFieldLengthDemo.insertOne({"UserId":4, "UserName":"John Smith"}); { "acknowledged" : ... 閱讀更多
32K+ 閱讀量
要在 MongoDB 中搜索物件陣列,可以使用 $elemMatch 運算子。此運算子允許我們從物件陣列中搜索多個元件。為了理解上述概念,讓我們建立一個包含文件的集合。建立包含文件的集合的查詢如下:> db.searchArrayDemo.insertOne({"EmployeeFirstName":"Adam", "EmployeeLastName":"Smith", "EmployeeDateOfBirth":new ISODate("1992-01-31 13:45:10"), ... "EmployeeSkills":["Spring and Hibernate Framework", "Machine Learning"], ... "EmployeeDetails":[ ... { ... "EmployeePerformanceArea":"Java", ... "Year":2001 ... }, ... { ... ... 閱讀更多
2K+ 閱讀量
在 MongoDB 中,不存在將一個數據庫中的集合複製到另一個數據庫的命令。要實現此目的,請使用以下概念:db.yourCollectionName.find().forEach(function(yourVariableName){ db.getSiblingDB('yourDestinationDatabase')['yourCollectionName'].insert(yourVariableName); });讓我們在 test 資料庫中建立一個集合,並將此集合複製到另一個名為“sample”的資料庫。為了理解上述語法,讓我們建立一個包含文件的集合。建立包含文件的集合的查詢如下:> use test switched to db test > db.copyThisCollectionToSampleDatabaseDemo.insertOne({"User_Id":101, "UserName":"Larr y"}); { "acknowledged" : true, "insertedId" : ObjectId("5c77ad622386c62d05142a67") } > db.copyThisCollectionToSampleDatabaseDemo.insertOne({"User_Id":102, "UserName":"Maxwell"}); { "acknowledged" : true, ... 閱讀更多
192 閱讀量
如果要列出特定資料庫中的所有集合,則需要先切換到該資料庫。查詢如下:> use sample; switched to db sample > db.getCollectionNames();以下是輸出:[ "copyThisCollectionToSampleDatabaseDemo", "deleteDocuments", "deleteDocumentsDemo", "deleteInformation", "employee", "internalArraySizeDemo", "sourceCollection", "updateInformation", "userInformation" ]另一種查詢可以是:> show collections;以下是輸出:copyThisCollectionToSampleDatabaseDemo deleteDocuments deleteDocumentsDemo deleteInformation employee internalArraySizeDemo sourceCollection updateInformation userInformation
337 閱讀量
要按升序排序,語法如下:db.yourCollectionName.find().sort({yourField:1});為了理解這個概念,讓我們建立一個包含文件的集合。建立包含文件的集合的查詢如下:> db.sortingDemo.insertOne({"Value":100}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e2ed3c9d04998abf006") } > db.sortingDemo.insertOne({"Value":1}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e31d3c9d04998abf007") } > db.sortingDemo.insertOne({"Value":150}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e34d3c9d04998abf008") } > db.sortingDemo.insertOne({"Value":250}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e37d3c9d04998abf009") } > db.sortingDemo.insertOne({"Value":5}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e3bd3c9d04998abf00a") } > db.sortingDemo.insertOne({"Value":199}); { "acknowledged" : ... 閱讀更多
198 閱讀量
要按升序排序,語法如下:db.yourCollectionName.find().sort({yourField:1});為了理解這個概念,讓我們建立一個包含文件的集合。建立包含文件的集合的查詢如下:> db.sortingDemo.insertOne({"Value":100}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e2ed3c9d04998abf006") } > db.sortingDemo.insertOne({"Value":1}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e31d3c9d04998abf007") } > db.sortingDemo.insertOne({"Value":150}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e34d3c9d04998abf008") } > db.sortingDemo.insertOne({"Value":250}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e37d3c9d04998abf009") } > db.sortingDemo.insertOne({"Value":5}); { "acknowledged" : true, "insertedId" : ObjectId("5c8f8e3bd3c9d04998abf00a") } > db.sortingDemo.insertOne({"Value":199}); { "acknowledged" : ... 閱讀更多
391 閱讀量
您可以在 MongoDB 中使用 distinct() 方法獲取不同的記錄值。語法如下:db.yourCollectionName.distinct(“yourFieldName”);為了理解上述語法,讓我們建立一個包含文件的集合。建立包含文件的集合的查詢如下:> db.distinctRecordDemo.insertOne({"StudentId":1, "StudentName":"John", "StudentAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5c77a78299b97a65744c1b50") } > db.distinctRecordDemo.insertOne({"StudentId":2, "StudentName":"John", "StudentAge":22}); { "acknowledged" : true, "insertedId" : ObjectId("5c77a78b99b97a65744c1b51") } > db.distinctRecordDemo.insertOne({"StudentId":3, "StudentName":"Carol", "StudentAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5c77a79a99b97a65744c1b52") } > db.distinctRecordDemo.insertOne({"StudentId":4, "StudentName":"Carol", "StudentAge":26}); { "acknowledged" : true, "insertedId" : ObjectId("5c77a7a499b97a65744c1b53") } > db.distinctRecordDemo.insertOne({"StudentId":5, "StudentName":"Sam", "StudentAge":24}); ... 閱讀更多
243 次檢視
您可以藉助聚合框架來實現此目的。為了理解這個概念,讓我們建立一個包含文件的集合。建立包含文件的集合的查詢如下:> db.countGroupByDemo.insertOne({"StudentId":10, "StudentName":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7700871e9c5dd6f1f78296") } > db.countGroupByDemo.insertOne({"StudentId":10, "StudentName":"Carol"}); { "acknowledged" : true, "insertedId" : ObjectId("5c77008f1e9c5dd6f1f78297") } > db.countGroupByDemo.insertOne({"StudentId":20, "StudentName":"Sam"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7700971e9c5dd6f1f78298") } > db.countGroupByDemo.insertOne({"StudentId":30, "StudentName":"Mike"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7700a21e9c5dd6f1f78299") } > db.countGroupByDemo.insertOne({"StudentId":30, "StudentName":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5c7700aa1e9c5dd6f1f7829a") } ... 閱讀更多
2K+ 閱讀量
您可以為此使用 $ne(不等於)運算子。為了理解這個概念,讓我們建立一個包含文件的集合。建立包含文件的集合的查詢如下:> db.arrayFieldIsNotEmptyDemo.insertOne({"StudentName":"Larry", "StudentTechnicalSubject":["Java", "C"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c76fe2f1e9c5dd6f1f78291") } > db.arrayFieldIsNotEmptyDemo.insertOne({"StudentName":"Mike", "StudentTechnicalSubject":[]}); { "acknowledged" : true, "insertedId" : ObjectId("5c76fe3b1e9c5dd6f1f78292") } > db.arrayFieldIsNotEmptyDemo.insertOne({"StudentName":"Sam", "StudentTechnicalSubject":["MongoDB"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c76fe491e9c5dd6f1f78293") } > db.arrayFieldIsNotEmptyDemo.insertOne({"StudentName":"Carol", "StudentTechnicalSubject":[]}); { "acknowledged" : true, "insertedId" : ObjectId("5c76fe521e9c5dd6f1f78294") } > db.arrayFieldIsNotEmptyDemo.insertOne({"StudentName":"David", "StudentTechnicalSubject":["MySQL", "SQL Server"]}); { "acknowledged" : true, "insertedId" : ObjectId("5c76fe661e9c5dd6f1f78295") }顯示所有文件 ... 閱讀更多
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP