找到 1660 篇文章 适用于大数据分析
660 次浏览
要查询嵌套数组,请在 MongoDB 中使用 $elemMatch。让我们创建一个包含文档的集合 -> db.demo203.insertOne({ ... "_id" : "101", ... "Name" : "Chris", ... "details1" : [ ... { ... "empName" : "David", ... "salary" : "50000", ... "technology" : [ ... "MySQL", ... "MongoDB" ... ] ... }, ... { ... "empName" : "Carol", ... ... 阅读更多
308 次浏览
有关查询计划的信息,请在 MongoDB 中使用 explain()。让我们创建一个包含文档的集合 -> db.demo202.insertOne({"StudentFirstName":"Chris", "StudentAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5e3c3bd103d395bdc21346e8") } > db.demo202.insertOne({"StudentFirstName":"David", "StudentAge":23}); { "acknowledged" : true, "insertedId" : ObjectId("5e3c3bd803d395bdc21346e9") } > db.demo202.insertOne({"StudentFirstName":"Bob", "StudentAge":22}); { "acknowledged" : true, "insertedId" : ObjectId("5e3c3bde03d395bdc21346ea") }显示使用 find() 方法从集合中获取所有文档 -> db.demo202.find();这将产生以下输出 -{ "_id" : ObjectId("5e3c3bd103d395bdc21346e8"), "StudentFirstName" : "Chris", "StudentAge" : 21 } { "_id" : ObjectId("5e3c3bd803d395bdc21346e9"), "StudentFirstName" : "David", "StudentAge" : 23 } { "_id" : ObjectId("5e3c3bde03d395bdc21346ea"), "StudentFirstName" ... 阅读更多
208 次浏览
要仅更新特定值,请使用 update(),并在其中使用 $set 设置新值。让我们创建一个包含文档的集合 -> db.demo201.insertOne({"ClientName":"Chris Brown", "ClientAge":26}); { "acknowledged" : true, "insertedId" : ObjectId("5e3c39ca03d395bdc21346e5") } > db.demo201.insertOne({"ClientName":"David Miller", "ClientAge":35}); { "acknowledged" : true, "insertedId" : ObjectId("5e3c39d403d395bdc21346e6") } > db.demo201.insertOne({"ClientName":"Carol Taylor", "ClientAge":28}); { "acknowledged" : true, "insertedId" : ObjectId("5e3c39e603d395bdc21346e7") }显示使用 find() 方法从集合中获取所有文档 -> db.demo201.find();这将产生以下输出 -{ "_id" : ObjectId("5e3c39ca03d395bdc21346e5"), "ClientName" : "Chris Brown", "ClientAge" : 26 } { "_id" : ObjectId("5e3c39d403d395bdc21346e6"), ... 阅读更多
401 次浏览
要过滤 MongoDB 中的多个子文档,请使用 aggregate()。让我们创建一个包含文档的集合 -> db.demo200.insertOne( ... { ... "Id":"101", ... "details1":[ ... { ... "isActive":true, ... "SubjectName":"MySQL" ... }, { ... "isActive":false, ... "SubjectName":"Java" ... } ... ], ... "details2":[ ... { ... "isActive":false, ... ... 阅读更多
295 次浏览
为此,请使用 $pull 以及 update。让我们创建一个包含文档的集合 -> db.demo198.insertOne({"List":{"Values":[10, 20, 30, 30, 70, 80, 90]}}); { "acknowledged" : true, "insertedId" : ObjectId("5e3c224503d395bdc21346df") } > db.demo198.insertOne({"List":{"Values":[56, 978, 56, 34, 23, 34]}}); { "acknowledged" : true, "insertedId" : ObjectId("5e3c225403d395bdc21346e0") } > db.demo198.insertOne({"List":{"Values":[21, 12, 14, 15, 34, 56]}}); { "acknowledged" : true, "insertedId" : ObjectId("5e3c226603d395bdc21346e1") }显示使用 find() 方法从集合中获取所有文档 -> db.demo198.find();这将产生以下输出 -{ "_id" : ObjectId("5e3c224503d395bdc21346df"), "List" : { "Values" : [ 10, 20, 30, 30, 70, 80, ... 阅读更多
86 次浏览
不会,使用 LIMIT() 会降低带宽消耗,但不会提高查询速度。让我们看一个示例并创建一个包含文档的集合 -> db.demo197.insertOne({"Name":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3afde803d395bdc21346d8") } > db.demo197.insertOne({"Name":"Bob"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3afdef03d395bdc21346d9") } > db.demo197.insertOne({"Name":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3afdf203d395bdc21346da") } > db.demo197.insertOne({"Name":"Sam"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3afdf603d395bdc21346db") } > db.demo197.insertOne({"Name":"Mike"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3afdf903d395bdc21346dc") } > db.demo197.insertOne({"Name":"Carol"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3afe1603d395bdc21346dd") } > db.demo197.insertOne({"Name":"John"}); { ... 阅读更多
461 次浏览
让我们创建一个包含文档的集合 -> db.demo196.insertOne( ... { ... ... "Id" : "101", ... "details" : [ ... { ... "FirstName" : "Chris", ... "LastName" : "Brown", ... "Score" : 45 ... }, ... { ... "FirstName" : "David", ... "LastName" : "Miller", ... "Score" : 87 ... ... 阅读更多
347 次浏览
要返回特定值的列表,请使用 map()。让我们创建一个包含文档的集合 -> db.demo195.insertOne({"Subject":"MySQL"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3af3f203d395bdc21346d4") } > db.demo195.insertOne({"Subject":"MongoDB"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3af3f703d395bdc21346d5") } > db.demo195.insertOne({"Subject":"Java"}); { "acknowledged" : true, "insertedId" : ObjectId("5e3af3fa03d395bdc21346d6") }显示使用 find() 方法从集合中获取所有文档 -> db.demo195.find();这将产生以下输出 -{ "_id" : ObjectId("5e3af3f203d395bdc21346d4"), "Subject" : "MySQL" } { "_id" : ObjectId("5e3af3f703d395bdc21346d5"), "Subject" : "MongoDB" } { "_id" : ObjectId("5e3af3fa03d395bdc21346d6"), "Subject" : "Java" }以下是如何返回 ... 阅读更多
149 次浏览
首先,让我们创建一个包含文档的集合 -> db.demo194.insertOne( ... { ... "_id": 101, ... "details": { ... "otherDetails": { ... "List1": ["MongoDB", "MySQL"], ... "List2": ["Java"], ... "List3": ["MongoDB", "C"] ... } ... } ... } ...); { "acknowledged" : true, "insertedId" : 101 } > db.demo194.insertOne( {"_id": 102, "details": { "otherDetails": { "List1": ["Java", "C"], "List2": ["C++"], "List3": ["Python", "Spring"] } } } ... 阅读更多