找到 1660 篇文章,关于大数据分析
197 次浏览
为了提高查询的执行时间,请使用索引以及 unique:true。让我们创建一个包含文档的集合 −> db.demo193.createIndex({"LastName":1}, {unique:true}); { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } > db.demo193.insertOne({"FirstName":"John", "LastName":"Doe"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3ade1803d395bdc21346d1") } > db.demo193.insertOne({"FirstName":"John", "LastName":"Smith"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3ade1f03d395bdc21346d2") } > db.demo193.insertOne({"FirstName":"David", "LastName":"Miller"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3ade2803d395bdc21346d3") }使用 find() 方法显示集合中的所有文档 −> db.demo193.find();这将产生以下输出 −{ "_id" ... 阅读更多
148 次浏览
要对多个字段进行分组,请在 MongoDB 中使用 $group。让我们创建一个包含文档的集合 −> db.demo192.insertOne({"Name":"Chris", "Age":22}); { "acknowledged" : true, "insertedId" : ObjectId("5e3adb9f03d395bdc21346cd") } > db.demo192.insertOne({"Name":"David", "Age":21}); { "acknowledged" : true, "insertedId" : ObjectId("5e3adba103d395bdc21346ce") } > db.demo192.insertOne({"Name":"Chris", "Age":22}); { "acknowledged" : true, "insertedId" : ObjectId("5e3adba503d395bdc21346cf") } > db.demo192.insertOne({"Name":"Mike", "Age":24}); { "acknowledged" : true, "insertedId" : ObjectId("5e3adbbf03d395bdc21346d0") }使用 find() 方法显示集合中的所有文档 −> db.demo192.find();这将产生以下输出 −{ "_id" : ObjectId("5e3adb9f03d395bdc21346cd"), "Name" : "Chris", "Age" : 22 } { "_id" : ObjectId("5e3adba103d395bdc21346ce"), ... 阅读更多
587 次浏览
要在 MongoDB 中获取游标的值,请使用 hasNext()。让我们创建一个包含文档的集合 −> db.demo191.insertOne({"EmployeeId":1, "EmployeeName":"Chris Brown"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3ad95303d395bdc21346c5") } > db.demo191.insertOne({"EmployeeId":2, "EmployeeName":"David Miller"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3ad95f03d395bdc21346c6") } > db.demo191.insertOne({"EmployeeId":1, "EmployeeName":"John Doe"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3ad96803d395bdc21346c7") } > db.demo191.insertOne({"EmployeeId":1, "EmployeeName":"John Smith"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3ad97003d395bdc21346c8") }使用 find() 方法显示集合中的所有文档 −> db.demo191.find();这将产生以下输出 −{ "_id" : ObjectId("5e3ad95303d395bdc21346c5"), "EmployeeId" : 1, "EmployeeName" : "Chris ... 阅读更多
506 次浏览
要实现具有多个键的聚合,请使用 aggregate() 和 $group。让我们创建一个包含文档的集合 −> db.demo190.insertOne( ... { ... ... "DueDate" : ISODate("2020-01-01"), ... "Value" : 10, ... "Name" : "Chris" ... } ...); { "acknowledged" : true, "insertedId" : ObjectId("5e3ad76403d395bdc21346bf") } > > db.demo190.insertOne( ... { ... ... "DueDate" : ISODate("2020-02-05"), ... "Value" : 30, ... "Name" : "David" ... } ...); { "acknowledged" : true, "insertedId" : ObjectId("5e3ad76403d395bdc21346c0") } > db.demo190.insertOne( ... { ... 阅读更多
389 次浏览
要查找多次出现的值,请在 MongoDB 中使用 $where。让我们创建一个包含文档的集合 −> db.demo188.insertOne( ... { ... "ListOfData":[ ... {"Data": 100}, ... {"Data": 200}, ... {"Data": 100} ... ] ... } ...); { "acknowledged" : true, "insertedId" : ObjectId("5e3ad1c203d395bdc21346bd") } > db.demo188.insertOne( ... { ... "ListOfData":[ ... {"Data": 100}, ... {"Data": 200}, ... {"Data": 300} ... } ...); { ... 阅读更多
143 次浏览
让我们首先创建一个包含文档的集合 −> db.demo187.insertOne( ... { ... "_id" : "101", ... "Details" : [ ... { "Subject" : "MongoDB" }, ... { "Subject" : "MySQL" } ... ] ... } ...); { "acknowledged" : true, "insertedId" : "101" } > db.demo187.insertOne( ... { ... "_id" : "102", ... "Details" : [ ... { } ... ] ... } ...); { "acknowledged" : true, "insertedId" : "102" ... 阅读更多
231 次浏览
让我们首先创建一个包含文档的集合 −> db.demo186.insertOne({"UserEmailId":"[email protected]", "UserName":"John"}); { "acknowledged" : true, "insertedId" : ObjectId("5e399d769e4f06af55199808") } > db.demo186.insertOne({"UserEmailId":"[email protected]", "UserName":"chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e399d879e4f06af55199809") } > db.demo186.insertOne({"UserEmailId":"[email protected]", "UserName":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e399d979e4f06af5519980a") }使用 find() 方法显示集合中的所有文档 −> db.demo186.find();这将产生以下输出 −{ "_id" : ObjectId("5e399d769e4f06af55199808"), "UserEmailId" : "[email protected]", "UserName" : "John" } { "_id" : ObjectId("5e399d879e4f06af55199809"), "UserEmailId" : "[email protected]", "UserName" : "chris" } { "_id" : ObjectId("5e399d979e4f06af5519980a"), "UserEmailId" : "[email protected]", "UserName" : "David" }以下是 ... 阅读更多
73 次浏览
要根据是否存在使用 $or 获取记录,请使用 $or 和 $exists。让我们创建一个包含文档的集合 −>db.demo185.insertOne({_id:101, details:{Name:"Chris", Score:78, Subjects:{"Name":"MySQL"}}}); { "acknowledged" : true, "insertedId" : 101 } > db.demo185.insertOne({_id:102, details:{Name:"Bob", Score:78}}); { "acknowledged" : true, "insertedId" : 102 } >db.demo185.insertOne({_id:103, details:{Name:"David", Score:78, Subjects:{"Name":"MongoDB"}}}); { "acknowledged" : true, "insertedId" : 103 }使用 find() 方法显示集合中的所有文档 −> db.demo185.find();这将产生以下输出 −{ "_id" : 101, "details" : { "Name" : "Chris", "Score" : 78, "Subjects" : { "Name" : "MySQL" } } } { "_id" ... 阅读更多
757 次浏览
要进行计数,您还可以使用 aggregate() 和 $sum。让我们创建一个包含文档的集合 −> db.demo184.insertOne({"Names":["Chris", "David", "Bob"]}); { "acknowledged" : true, "insertedId" : ObjectId("5e3999fb9e4f06af55199805") } > db.demo184.insertOne({"Names":["Chris", "Mike"]}); { "acknowledged" : true, "insertedId" : ObjectId("5e399a0d9e4f06af55199806") } > db.demo184.insertOne({"Names":["Chris", "Bob", "Carol"]}); { "acknowledged" : true, "insertedId" : ObjectId("5e399a209e4f06af55199807") }使用 find() 方法显示集合中的所有文档 −> db.demo184.find();这将产生以下输出 −{ "_id" : ObjectId("5e3999fb9e4f06af55199805"), "Names" : [ "Chris", "David", "Bob" ] } { "_id" : ObjectId("5e399a0d9e4f06af55199806"), "Names" : [ "Chris", "Mike" ] } { ... 阅读更多