找到 1660 篇文章 关于大数据分析
401 次浏览
要按另一个字段分组,请使用 $group 和 $project。让我们首先创建一个包含文档的集合 −> db.demo374.insertOne( ... { ... ... "Name" : "Chris", ... "HobbyDetails" : [ ... "Reading Book", ... "Playing Football" ... ], ... "CountryName" : "US" ... } ... ); { "acknowledged" : true, "insertedId" : ObjectId("5e5a04402ae06a1609a00b04") } > db.demo374.insertOne( ... { ... ... 阅读更多
339 次浏览
让我们首先创建一个包含文档的集合 −> db.demo373.createIndex({"Name":1, "CountryName":1}); { "createdCollectionAutomatically" : true, "numIndexesBefore" : 1, "numIndexesAfter" : 2, "ok" : 1 } > db.demo373.insertOne({"Name":"Chris", "Age":22, "CountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5e59ffde2ae06a1609a00aff") } > db.demo373.insertOne({"Name":"David", "Age":21, "CountryName":"AUS"}); { "acknowledged" : true, "insertedId" : ObjectId("5e59ffe82ae06a1609a00b00") } > db.demo373.insertOne({"Name":"Bob", "Age":23, "CountryName":"UK"}); { "acknowledged" : true, "insertedId" : ObjectId("5e59fff42ae06a1609a00b01") } > db.demo373.insertOne({"Name":"John", "Age":21, "CountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5e59ffff2ae06a1609a00b02") } > db.demo373.insertOne({"Name":"Carol", "Age":23, "CountryName":"AUS"}); { "acknowledged" : true, "insertedId" : ObjectId("5e5a00082ae06a1609a00b03") }显示所有 ... 阅读更多
2K+ 次浏览
$ifNull 评估表达式,如果表达式的结果为非空值,则返回表达式的值。让我们首先创建一个包含文档的集合 −> db.demo372.insertOne({"FirstName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5e591aea2ae06a1609a00af6") } > db.demo372.insertOne({"FirstName":null}); { "acknowledged" : true, "insertedId" : ObjectId("5e591aef2ae06a1609a00af7") } > db.demo372.insertOne({"FirstName":"David"}); { "acknowledged" : true, "insertedId" : ObjectId("5e591af42ae06a1609a00af8") } > db.demo372.insertOne({"FirstName":null}); { "acknowledged" : true, "insertedId" : ObjectId("5e591afb2ae06a1609a00af9") }使用 find() 方法显示集合中的所有文档 −> db.demo372.find();这将产生以下输出 −{ "_id" : ObjectId("5e591aea2ae06a1609a00af6"), "FirstName" : "Chris" ... 阅读更多
1K+ 次浏览
要更改主键,您需要先将其删除。使用 forEach() 和 delete 来删除,然后获取新的主键。让我们创建一个包含文档的集合 −> db.demo41.insertOne({"StudentName":"Carol"}); { "acknowledged" : true, "insertedId" : ObjectId("5e25ce4acfb11e5c34d898e3") }使用 find() 方法显示集合中的所有文档 −> db.demo41.find();这将产生以下输出 −{ "_id" : ObjectId("5e25ce4acfb11e5c34d898e3"), "StudentName" : "Carol" }以下是更改 MongoDB 集合主键的查询 −> var next = db.demo41.find() > > next.forEach(function(s) { ... var prevId=s._id; ... delete s._id; ... ... 阅读更多
2K+ 次浏览
为此,请在 MongoDB 中使用 save()。以下是语法 −var anyVaribaleName=yourValue db.anyCollectionName.save(yourVariableName); yourVariableName;让我们首先为我们的示例创建一个对象 −> var studentDetails={"StudentName":"Chris","ListOfMarks":[56,78,89],"ListOfSubject":["MySQL","Java","MongoDB"]};让我们保存上面创建的对象“studentDetails” −> db.demo40.save(studentDetails); WriteResult({ "nInserted" : 1 })让我们显示该值 −> studentDetails;这将产生以下输出 −{ "StudentName" : "Chris", "ListOfMarks" : [ 56, 78, 89 ], "ListOfSubject" : [ "MySQL", "Java", "MongoDB" ], "_id" : ObjectId("5e177757cfb11e5c34d898e2") }
273 次浏览
让我们首先创建一个包含文档的集合 −> db.demo371.insertOne({"Name":"David", "CountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5e57f6982ae06a1609a00af2") } > db.demo371.insertOne({"Name":"John", "CountryName":"UK"}); { "acknowledged" : true, "insertedId" : ObjectId("5e57f69e2ae06a1609a00af3") } > db.demo371.insertOne({"Name":"Bob", "CountryName":"AUS"}); { "acknowledged" : true, "insertedId" : ObjectId("5e57f6a42ae06a1609a00af4") } > db.demo371.insertOne({"Name":"Mike", "CountryName":"US"}); { "acknowledged" : true, "insertedId" : ObjectId("5e57f6ba2ae06a1609a00af5") }使用 find() 方法显示集合中的所有文档 −> db.demo371.find();这将产生以下输出 −{ "_id" : ObjectId("5e57f6982ae06a1609a00af2"), "Name" : "David", "CountryName" : "US" } { "_id" : ObjectId("5e57f69e2ae06a1609a00af3"), "Name" : "John", "CountryName" : "UK" } ... 阅读更多
123 次浏览
首先,使用 USE 命令切换到 MongoDB 中的特定数据库,如下面的语法所示 −use yourDatabaseName; db.getCollectionNames();让我们实现上述语法以显示数据库 WEB 的集合 −> use web; switched to db web > db.getCollectionNames();这将产生以下输出 −[ "2015-myCollection", "2015-yourCollection", "2019-employeeCollection", "addColumnDemo", "applyConditionDemo", "calculateAverage", "calculateSumOfDocument", "changeSimpleFieldDemo", "check", "checkFieldDemo", "collationExample", "compoundIndexDemo", "countandsumdemo", "creatingAliasDemo", "decreasetimeusingindex", "demo1", "demo10", "demo11", "demo12", "demo13", "demo14", "demo15", "demo16", "demo17", "demo18", ... 阅读更多
66 次浏览
为此,请使用位置运算符 ($) 。要将字段值递增 1,请使用 $inc 运算符。让我们创建一个包含文档的集合 −>db.demo39.insertOne({"ProductDetails":[{"ProductName":"Product-1", "ProductPrice":349}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e176d54cfb11e5c34d898df") } >db.demo39.insertOne({"ProductDetails":[{"ProductName":"Product-2", "ProductPrice":998}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e176d61cfb11e5c34d898e0") } >db.demo39.insertOne({"ProductDetails":[{"ProductName":"Product-3", "ProductPrice":145}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e176d6acfb11e5c34d898e1") }使用 find() 方法显示集合中的所有文档 −> db.demo39.find();这将产生以下输出 −{ "_id" : ObjectId("5e176d54cfb11e5c34d898df"), "ProductDetails" : [ { "ProductName" : "Product-1", "ProductPrice" : 349 } ] } { "_id" : ObjectId("5e176d61cfb11e5c34d898e0"), "ProductDetails" : [ ... 阅读更多
浏览量:77
要从 find 查询中检索数组值,请使用点表示法。让我们创建一个包含文档的集合:-> db.demo38.insertOne({"ClientDetails":[{"ClientId":101, "ClientName":"Chris"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e176abccfb11e5c34d898d9") } > db.demo38.insertOne({"ClientDetails":[{"ClientId":102, "ClientName":"David"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e176ac7cfb11e5c34d898da") } > db.demo38.insertOne({"ClientDetails":[{"ClientId":103, "ClientName":"Mike"}]}); { "acknowledged" : true, "insertedId" : ObjectId("5e176ad0cfb11e5c34d898db") } 使用 find() 方法显示集合中的所有文档:-> db.demo38.find(); 这将产生以下输出:{ "_id" : ObjectId("5e176abccfb11e5c34d898d9"), "ClientDetails" : [ { "ClientId" : 101, "ClientName" : "Chris" } ] } { "_id" : ObjectId("5e176ac7cfb11e5c34d898da"), "ClientDetails" : [ { ... 阅读更多