找到关于大数据分析的1660篇文章
249 次浏览
让我们首先创建一个包含文档的集合 −>db.demo144.insertOne({"EmployeeDetails":[{"EmployeeName":"Chris", "EmployeeEmail":"[email protected]"}, {"EmployeeName":"Bob", "EmployeeEmail":"[email protected]"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e32f1d8fdf09dd6d08539b9") } >db.demo144.insertOne({"EmployeeDetails":[{"EmployeeName":"David", "EmployeeEmail":"[email protected]"}, {"EmployeeName":"Carol", "EmployeeEmail":"[email protected]"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e32f1f5fdf09dd6d08539ba") } 使用 find() 方法显示集合中的所有文档 −> db.demo144.find(); 这将产生以下输出 −{ "_id" : ObjectId("5e32f1d8fdf09dd6d08539b9"), "EmployeeDetails" : [ { "EmployeeName" : "Chris", "EmployeeEmail" : "[email protected]" }, { "EmployeeName" : "Bob", "EmployeeEmail" : "[email protected]" } ] } { "_id" : ObjectId("5e32f1f5fdf09dd6d08539ba"), "EmployeeDetails" : [ { "EmployeeName" ... 阅读更多
791 次浏览
为此,只需使用 update() 进行更新。让我们创建一个包含文档的集合 −> db.dem0143.insertOne({"StudentId":1, "Details":{"Name":"Chris"}}); { "acknowledged" : true, "insertedId" : ObjectId("5e32eb9efdf09dd6d08539b7") } > db.dem0143.insertOne({"StudentId":2, "Details":{"Name":"David"}}); { "acknowledged" : true, "insertedId" : ObjectId("5e32eba5fdf09dd6d08539b8") } 使用 find() 方法显示集合中的所有文档 −> db.dem0143.find(); 这将产生以下输出 −{ "_id" : ObjectId("5e32eb9efdf09dd6d08539b7"), "StudentId" : 1, "Details" : { "Name" : "Chris" } } { "_id" : ObjectId("5e32eba5fdf09dd6d08539b8"), "StudentId" : 2, "Details" : { "Name" : "David" } } 以下是单个更新中实现 $set 和 $push 的查询 ... 阅读更多
788 次浏览
为此,您可以使用 aggregate()。让我们创建一个包含文档的集合 −> db.demo142.insertOne({"Value":50}); { "acknowledged" : true, "insertedId" : ObjectId("5e32e9c6fdf09dd6d08539b2") } > db.demo142.insertOne({"Value":45}); { "acknowledged" : true, "insertedId" : ObjectId("5e32e9cafdf09dd6d08539b3") } > db.demo142.insertOne({"Value":60}); { "acknowledged" : true, "insertedId" : ObjectId("5e32e9cdfdf09dd6d08539b4") } > db.demo142.insertOne({"Value":55}); { "acknowledged" : true, "insertedId" : ObjectId("5e32e9d0fdf09dd6d08539b5") } > db.demo142.insertOne({"Value":50}); { "acknowledged" : true, "insertedId" : ObjectId("5e32e9d9fdf09dd6d08539b6") } 使用 find() 方法显示集合中的所有文档 −> db.demo142.find(); 这将产生以下输出 −{ "_id" : ObjectId("5e32e9c6fdf09dd6d08539b2"), "Value" : 50 } { ... 阅读更多
6K+ 次浏览
要查找集合中的最后一个对象,首先使用 sort() 对值进行排序。使用 limit() 获取值的数量,即如果您只想获取最后一个对象,则使用 limit(1)。让我们首先创建一个包含文档的集合 −> db.demo141.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e31c347fdf09dd6d08539ae") } > db.demo141.insertOne({"Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e31c34bfdf09dd6d08539af") } > db.demo141.insertOne({"Name":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e31c34ffdf09dd6d08539b0") } > db.demo141.insertOne({"Name":"Mike"}); { "acknowledged" : true, "insertedId" : ObjectId("5e31c352fdf09dd6d08539b1") } 使用 find() 方法显示集合中的所有文档 −> db.demo141.find(); 这将 ... 阅读更多
236 次浏览
对于这种类型的获取,只使用 $nin 和 $in。让我们创建一个包含文档的集合 −> db.demo140.insertOne({"Id":101, "Subjects":["MongoDB", "MySQL"]}); { "acknowledged" : true, "insertedId" : ObjectId("5e31c149fdf09dd6d08539a9") } > db.demo140.insertOne({"Id":102, "Subjects":["MongoDB", "Java"]}); { "acknowledged" : true, "insertedId" : ObjectId("5e31c14cfdf09dd6d08539aa") } > db.demo140.insertOne({"Id":103, "Subjects":["MongoDB", "PL/SQL"]}); { "acknowledged" : true, "insertedId" : ObjectId("5e31c157fdf09dd6d08539ab") } > db.demo140.insertOne({"Id":104, "Subjects":["MongoDB", "SQL Server"]}); { "acknowledged" : true, "insertedId" : ObjectId("5e31c163fdf09dd6d08539ac") } > db.demo140.insertOne({"Id":105, "Subjects":["C", "C++"]}); { "acknowledged" : true, "insertedId" : ObjectId("5e31c16ffdf09dd6d08539ad") } 使用 find() 方法显示集合中的所有文档 −> ... 阅读更多
863 次浏览
为此,使用 aggregate()。让我们创建一个包含文档的集合 −>db.demo138.insertOne({"Id":101, "PlayerDetails":[{"PlayerName":"Chris", "PlayerScore":400}, {"PlayerName":"David", "PlayerScore":1000}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e31bb9ffdf09dd6d08539a1") } >db.demo138.insertOne({"Id":102, "PlayerDetails":[{"PlayerName":"Bob", "PlayerScore":500}, {"PlayerName":"Carol", "PlayerScore":600}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e31bbcefdf09dd6d08539a2") } 使用 find() 方法显示集合中的所有文档 −> db.demo138.find(); 这将产生以下输出 −{ "_id" : ObjectId("5e31bb9ffdf09dd6d08539a1"), "Id" : 101, "PlayerDetails" : [ { "PlayerName" : "Chris", "PlayerScore" : 400 }, { "PlayerName" : "David", "PlayerScore" : 1000 } ] } { "_id" : ObjectId("5e31bbcefdf09dd6d08539a2"), ... 阅读更多
1K+ 次浏览
为此,使用 aggregate() 和 $filter。让我们创建一个包含文档的集合 −> db.demo137.insertOne( ... { ... Name1:"Chris", ... Name2:"David", ... Detail1:[ ... {_id:"John", Name3:"Chris"}, ... {_id:"Chris", Name3:"Chris"}, ... ], ... Detail2:[{_id:"David", Name3:"Chris"}, ... {_id:"Carol", Name3:"Chris"}, ... {_id:"John", Name3:"Chris"}] ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e31b4cefdf09dd6d08539a0") } 使用 find() 方法显示集合中的所有文档 −> db.demo137.find(); 这将 ... 阅读更多
198 次浏览
要更新,请结合 UPDATE 使用 $set。让我们创建一个包含文档的集合:->db.demo135.insertOne({"Details":[{"EmployeeId":101, "EmployeeName":"Chris", "EmployeeSalary":45000}, {"EmployeeId":102, "EmployeeName":"Chris", "EmployeeSalary":45000}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e31a5ddfdf09dd6d085399c") } 使用 find() 方法显示集合中的所有文档:-> db.demo135.find().pretty(); 这将产生以下输出:-{ "_id" : ObjectId("5e31a5ddfdf09dd6d085399c"), "Details" : [ { "EmployeeId" : 101, "EmployeeName" : "Chris", "EmployeeSalary" : 45000 }, { "EmployeeId" : 102, ... 阅读更多
2K+ 次浏览
要更新,请结合 update() 使用 $set。让我们创建一个包含文档的集合:->db.demo134.insertOne({"EmployeeId":101, "EmployeeDetails":[{"EmployeeName":"Chris", "EmployeeAge":27}, {"EmployeeName":"Bob", "EmployeeAge":28}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e319b2f68e7f832db1a7f7c") } >db.demo134.insertOne({"EmployeeId":102, "EmployeeDetails":[{"EmployeeName":"David", "EmployeeAge":24}, {"EmployeeName":"Carol", "EmployeeAge":29}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e319b4468e7f832db1a7f7d") } 使用 find() 方法显示集合中的所有文档:-> db.demo134.find().pretty(); 这将产生以下输出:-{ "_id" : ObjectId("5e319b2f68e7f832db1a7f7c"), "EmployeeId" : 101, "EmployeeDetails" : [ { "EmployeeName" : "Chris", "EmployeeAge" : 27 }, ... 阅读更多