找到 1660 篇文章 关于大数据分析
246 次浏览
您可以为此使用 $set 运算符。以下是语法:db.yourCollectionName.update({"_id" : yourObjectId }, {$set: { "yourOuterFieldName.anyInnerFieldName": yourValue}});让我们首先创建一个包含文档的集合:> db.pushNewKeyDemo.insertOne({"UserId":100, "UserDetails":{}}); { "acknowledged" : true, "insertedId" : ObjectId("5cda58f5b50a6c6dd317adbf") }以下是使用 find() 方法显示集合中所有文档的查询:> db.pushNewKeyDemo.find();这将产生以下输出:{ "_id" : ObjectId("5cda58f5b50a6c6dd317adbf"), "UserId" : 100, "UserDetails" : { } }以下是将新的键元素推入 MongoDB 子文档中的查询:> db.pushNewKeyDemo.update({"_id" : ObjectId("5cda58f5b50a6c6dd317adbf")}, {$set: { "UserDetails.UserName": "David Miller"}}); WriteResult({ "nMatched" : 1, ... 阅读更多
351 次浏览
您可以使用 $pull 运算符从数组中删除字符串。让我们首先创建一个包含文档的集合:> db.removeAStringDemo.insertOne({"Score":[45, 67, 89, "John", 98, 99, 67]}); { "acknowledged" : true, "insertedId" : ObjectId("5cda5224b50a6c6dd317adbd") }以下是使用 find() 方法显示集合中所有文档的查询:> db.removeAStringDemo.find().pretty();这将产生以下输出:{ "_id" : ObjectId("5cda5224b50a6c6dd317adbd"), "Score" : [ 45, 67, 89, "John", 98, 99, 67 ] ... 阅读更多
61 次浏览
您可以为此使用 $where 运算符。让我们首先创建一个包含文档的集合:>db.veryStrictDocumentDemo.insertOne({"StudentFirstName":"John", "StudentLastName":"Doe", "StudentAge":23}); { "acknowledged" : true, "insertedId" : ObjectId("5cda4bcdb50a6c6dd317adb8") } > db.veryStrictDocumentDemo.insertOne({"StudentFirstName":"Larry"}); { "acknowledged" : true, "insertedId" : ObjectId("5cda4bdbb50a6c6dd317adb9") } >db.veryStrictDocumentDemo.insertOne({"StudentFirstName":"David", "StudentLastName":"Miller"}); { "acknowledged" : true, "insertedId" : ObjectId("5cda4becb50a6c6dd317adba") } > db.veryStrictDocumentDemo.insertOne({"StudentFirstName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5cda4bfbb50a6c6dd317adbb") } > db.veryStrictDocumentDemo.insertOne({"StudentFirstName":"Bob", "StudentLastName":"Brown"}); { "acknowledged" : true, "insertedId" : ObjectId("5cda4c6db50a6c6dd317adbc") }以下是使用 find() 方法显示集合中所有文档的查询:> db.veryStrictDocumentDemo.find();这将产生以下输出 ... 阅读更多
319 次浏览
您可以使用聚合框架。让我们首先创建一个包含文档的集合:> db.getArrayDemo.insertOne( { "CustomerId":101, "CustomerDetails":[ { "CustomerName":"Larry", "CustomerFriendDetails":[ { "CustomerFriendName":"Sam" }, { "CustomerFriendName":"Robert" } ... 阅读更多
477 次浏览
您可以为此使用 $gt 运算符。让我们首先创建一个包含文档的集合:> db.arrayElementsNotGreaterThanDemo.insertOne({"Scores":[89, 43, 32, 45]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9e9f9b50a6c6dd317adb3") } > db.arrayElementsNotGreaterThanDemo.insertOne({"Scores":[32, 33, 34, 40]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9ea13b50a6c6dd317adb4") } > db.arrayElementsNotGreaterThanDemo.insertOne({"Scores":[45, 56, 66, 69]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9ea25b50a6c6dd317adb5") } > db.arrayElementsNotGreaterThanDemo.insertOne({"Scores":[46, 66, 77, 88]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9ea3cb50a6c6dd317adb6") }以下是使用 find() 方法显示集合中所有文档的查询:> db.arrayElementsNotGreaterThanDemo.find().pretty();这将产生以下输出:{ ... 阅读更多
85 次浏览
是的,您可以将 capped 参数与最大大小一起使用。以下是语法:db.createCollection("yourCollectionName", {capped:true, size:yourSizeInBytes, max:howManyRecordsYouWant})让我们首先创建一个 capped:true 的集合:> db.createCollection("limitTheNumberOfRecordsDemo", {capped:true, size:200024, max:3}) { "ok" : 1 }我们现在将创建一个包含文档的集合:> db.limitTheNumberOfRecordsDemo.insertOne({"ClientName":"James Brown"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9e601b50a6c6dd317adad") } > db.limitTheNumberOfRecordsDemo.insertOne({"ClientName":"Sam Williams"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9e60bb50a6c6dd317adae") } > db.limitTheNumberOfRecordsDemo.insertOne({"ClientName":"David Miller"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9e612b50a6c6dd317adaf") } > db.limitTheNumberOfRecordsDemo.insertOne({"ClientName":"Carol Taylor"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9e61ab50a6c6dd317adb0") } > db.limitTheNumberOfRecordsDemo.insertOne({"ClientName":"Adam Smith"}); { "acknowledged" ... 阅读更多
98 次浏览
要在 MongoDB 中获取特定字段作为结果,您可以使用 findOne()。以下是语法:db.yourCollectionName.findOne({"yourFieldName1":yourValue}, {yourFieldName2:1});让我们首先创建一个包含文档的集合:> db.particularFieldDemo.insertOne({"EmployeeName":"John Smith", "EmployeeAge":26, "EmployeeTechnology":"MongoDB"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9b4abb50a6c6dd317ada2") } > db.particularFieldDemo.insertOne({"EmployeeName":"Chris Brown", "EmployeeAge":28, "EmployeeTechnology":"Java"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9b4d2b50a6c6dd317ada3") } > db.particularFieldDemo.insertOne({"EmployeeName":"David Miller", "EmployeeAge":30, "EmployeeTechnology":"MySQL"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9b4e8b50a6c6dd317ada4") } > db.particularFieldDemo.insertOne({"EmployeeName":"John Doe", "EmployeeAge":31, "EmployeeTechnology":"C++"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9b527b50a6c6dd317ada5") }以下是使用 ... 阅读更多
145 次浏览
让我们首先创建一个包含文档的集合,其中一个字段是 StudentName:> db.lowerCaseDemo.insertOne({"StudentName":"JOHN SMith"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9a86fb50a6c6dd317ad9f") } > db.lowerCaseDemo.insertOne({"StudentName":"CAROL TAYLor"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9a88fb50a6c6dd317ada0") } > db.lowerCaseDemo.insertOne({"StudentName":"DAVID Miller"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9a89fb50a6c6dd317ada1") }以下是使用 find() 方法显示集合中所有文档的查询:> db.lowerCaseDemo.find().pretty();这将产生以下输出:{ "_id" : ObjectId("5cd9a86fb50a6c6dd317ad9f"), "StudentName" : "JOHN SMith" } { "_id" : ObjectId("5cd9a88fb50a6c6dd317ada0"), "StudentName" : "CAROL TAYLor" } { ... 阅读更多
726 次浏览
使用带点符号的 find() 执行递归搜索。 让我们首先创建一个包含文档的集合 -> db.findOperationDemo.insertOne({"ClientDetails":[{"ClientId":101, "ClientName":"Chris"}, {"ClientId":102, "ClientName":"Robert"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9a118b50a6c6dd317ad99") } > db.findOperationDemo.insertOne({"ClientDetails":[{"ClientId":110, "ClientName":"David"}, {"ClientId":112, "ClientName":"Mike"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd9a12fb50a6c6dd317ad9a") }以下是使用 find() 方法显示集合中所有文档的查询 -> db.findOperationDemo.find().pretty();这将产生以下输出 -{ "_id" : ObjectId("5cd9a118b50a6c6dd317ad99"), "ClientDetails" : [ { "ClientId" : 101, "ClientName" : "Chris" ... 阅读更多
63 次浏览
使用 $addToSet 在 MongoDB 中创建新字段。 让我们首先创建一个包含文档的集合 -> db.createFieldDemo.insertOne({"StudentFirstName":"John", "StudentAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5cd99e28b50a6c6dd317ad95") } > db.createFieldDemo.insertOne({"StudentFirstName":"Larry", "StudentAge":23}); { "acknowledged" : true, "insertedId" : ObjectId("5cd99e2fb50a6c6dd317ad96") } > db.createFieldDemo.insertOne({"StudentFirstName":"Chris", "StudentAge":22}); { "acknowledged" : true, "insertedId" : ObjectId("5cd99e38b50a6c6dd317ad97") } > db.createFieldDemo.insertOne({"StudentFirstName":"David", "StudentAge":25}); { "acknowledged" : true, "insertedId" : ObjectId("5cd99e43b50a6c6dd317ad98") }以下是使用 find() 方法显示集合中所有文档的查询 -> db.createFieldDemo.find().pretty();这将产生以下输出 -{ "_id" : ObjectId("5cd99e28b50a6c6dd317ad95"), "StudentFirstName" : ... 阅读更多