找到关于大数据分析的1660 篇文章
360 次浏览
让我们首先看看删除集合的语法 - db.getCollection("yourCollectionNameWithTwoDashes").drop(); 为了演示,我们将创建一个名称包含双短横线的集合,如下所示 -> db.createCollection("company--EmployeeInformation"); { "ok" : 1 } 创建上述集合“company--EmployeeInformation”,并添加文档。查询如下:>db.getCollection("company--EmployeeInformation").insertOne({"CompanyName":"Amazon", "EmployeeName":"Chris"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7c5ff6d78f205348bc654") } >db.getCollection("company--EmployeeInformation").insertOne({"CompanyName":"Google", "EmployeeName":"Robert"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7c60b6d78f205348bc655") } 使用 find() 方法显示集合中所有文档的查询如下:> db.getCollection("company--EmployeeInformation").find(); 这将产生以下输出 -{ "_id" : ObjectId("5cd7c5ff6d78f205348bc654"), "CompanyName" : "Amazon", "EmployeeName" : "Chris" } { ... 阅读更多
295 次浏览
$exists 用于检查字段是否存在,而 $ne 用于不等条件。让我们首先创建一个包含文档的集合 -> db.existsDemo.insertOne({"Name":"Chris", "Age":21}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7c3916d78f205348bc650") } > db.existsDemo.insertOne({"Name":"", "Age":null}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7c39a6d78f205348bc651") } > db.existsDemo.insertOne({"Name":null, "Age":24}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7c3a66d78f205348bc652") } > db.existsDemo.insertOne({"Age":23}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7c3c36d78f205348bc653") } 使用 find() 方法显示集合中所有文档的查询如下:> db.existsDemo.find().pretty(); 这将产生以下输出 -{ "_id" : ObjectId("5cd7c3916d78f205348bc650"), "Name" : "Chris", "Age" : 21 } { "_id" : ObjectId("5cd7c39a6d78f205348bc651"), "Name" : "", "Age" ... 阅读更多
404 次浏览
让我们首先创建一个包含文档的集合 -> db.findOneWorkingDemo.insertOne({"ClientId":1, "ClientName":"Larry", "ClientAge":26}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7c1716d78f205348bc64d") } > db.findOneWorkingDemo.insertOne({"ClientId":2, "ClientName":"Chris", "ClientAge":28}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7c17d6d78f205348bc64e") } > db.findOneWorkingDemo.insertOne({"ClientId":3, "ClientName":"Robert", "ClientAge":34}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7c1896d78f205348bc64f") } 使用 find() 方法显示集合中所有文档的查询如下:> db.findOneWorkingDemo.find().pretty(); 这将产生以下输出 -{ "_id" : ObjectId("5cd7c1716d78f205348bc64d"), "ClientId" : 1, "ClientName" : "Larry", "ClientAge" : 26 } { "_id" : ObjectId("5cd7c17d6d78f205348bc64e"), "ClientId" : 2, ... 阅读更多
830 次浏览
要计算时间戳的差值,请使用聚合框架。让我们首先创建一个包含文档的集合 -> db.timestampDifferenceDemo.insertOne({ "MovieBeginningTime": new ISODate("2019-05-12 10:20:30"), "MovieEndingTime":new ISODate("2019-05-12 12:30:20") }); { "acknowledged" : true, "insertedId" : ObjectId("5cd7ba1f6d78f205348bc644") } > db.timestampDifferenceDemo.insertOne({ "MovieBeginningTime": new ISODate("2019-05-12 04:00:00"), "MovieEndingTime":new ISODate("2019-05-12 07:10:00") }); { "acknowledged" : true, "insertedId" : ObjectId("5cd7ba3b6d78f205348bc645") } 使用 find() 方法显示集合中所有文档的查询如下:> db.timestampDifferenceDemo.find().pretty(); 这将产生以下输出 -{ "_id" : ObjectId("5cd7ba1f6d78f205348bc644"), "MovieBeginningTime" : ISODate("2019-05-12T10:20:30Z"), "MovieEndingTime" : ISODate("2019-05-12T12:30:20Z") } { "_id" : ... 阅读更多
73 次浏览
是的,您可以使用 findOne()。语法如下:db.yourCollectionName.findOne(); 您也可以使用 toArray() - db.yourCollectionName.find().toArray(); 让我们首先创建一个包含文档的集合 -> db.betterFormatDemo.insertOne({"StudentName":"Adam Smith", "StudentScores":[98, 67, 89]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7ab826d78f205348bc640") } > db.betterFormatDemo.insertOne({"StudentName":"John Doe", "StudentScores":[67, 89, 56]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7ab936d78f205348bc641") } > db.betterFormatDemo.insertOne({"StudentName":"Sam Williams", "StudentScores":[45, 43, 33]}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7aba76d78f205348bc642") } 使用 find() 方法显示集合中所有文档的查询如下:> db.betterFormatDemo.find(); 这将产生以下输出 -{ "_id" : ObjectId("5cd7ab826d78f205348bc640"), "StudentName" ... 阅读更多
681 次浏览
让我们首先创建一个包含文档的集合 ->db.decrementingOperationDemo.insertOne({"ProductName":"Product-1", "ProductPrice":756}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7a8ae6d78f205348bc63c") } >db.decrementingOperationDemo.insertOne({"ProductName":"Product-2", "ProductPrice":890}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7a8b86d78f205348bc63d") } >db.decrementingOperationDemo.insertOne({"ProductName":"Product-3", "ProductPrice":994}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7a8c66d78f205348bc63e") } >db.decrementingOperationDemo.insertOne({"ProductName":"Product-4", "ProductPrice":1000}); { "acknowledged" : true, "insertedId" : ObjectId("5cd7a8d06d78f205348bc63f") } 使用 find() 方法显示集合中所有文档的查询如下:> db.decrementingOperationDemo.find().pretty(); 这将产生以下输出 -{ "_id" : ObjectId("5cd7a8ae6d78f205348bc63c"), "ProductName" : "Product-1", "ProductPrice" : 756 } { "_id" : ObjectId("5cd7a8b86d78f205348bc63d"), "ProductName" ... 阅读更多
114 次浏览
让我们首先创建一个包含文档的集合 -> db.matchingFirstItemInTheArrayDemo.insertOne( { "ClientDetails": [ { "ClientName": "Larry", "ClientAge":28 } ] } ); { "acknowledged" : true, "insertedId" : ObjectId("5cd7a5d26d78f205348bc636") } > db.matchingFirstItemInTheArrayDemo.insertOne( { "ClientDetails": [ { "ClientName": "Chris", "ClientAge":56, } ] } ); { "acknowledged" : true, "insertedId" : ObjectId("5cd7a5f56d78f205348bc637") } > db.matchingFirstItemInTheArrayDemo.insertOne( ... 阅读更多
687 次浏览
首先,让我们创建一个包含文档的集合:−> db.excludeIdDemo.insertOne({"StudentFirstName":"John", "StudentAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5cd701a56d78f205348bc632") } > db.excludeIdDemo.insertOne({"StudentFirstName":"Robert", "StudentAge":20}); { "acknowledged" : true, "insertedId" : ObjectId("5cd701af6d78f205348bc633") } > db.excludeIdDemo.insertOne({"StudentFirstName":"Chris", "StudentAge":24}); { "acknowledged" : true, "insertedId" : ObjectId("5cd701b86d78f205348bc634") }以下是使用find()方法显示集合中所有文档的查询:−> db.excludeIdDemo.find();这将产生以下输出:{ "_id" : ObjectId("5cd701a56d78f205348bc632"), "StudentFirstName" : "John", "StudentAge" : 21 } { "_id" : ObjectId("5cd701af6d78f205348bc633"), "StudentFirstName" : "Robert", "StudentAge" : 20 } { "_id" : ObjectId("5cd701b86d78f205348bc634"), "StudentFirstName" : "Chris", "StudentAge" ... 阅读更多
289 次浏览
要连接字段,请使用$concat运算符。首先,让我们创建一个包含文档的集合:−>db.concatenateFieldsDemo.insertOne({"StudentFirstName":"Adam", "StudentLastName":"Smith"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd6ebf46d78f205348bc62e") } >db.concatenateFieldsDemo.insertOne({"StudentFirstName":"John", "StudentLastName":"Doe"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd6ebfc6d78f205348bc62f") } >db.concatenateFieldsDemo.insertOne({"StudentFirstName":"David", "StudentLastName":"Miller"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd6ec376d78f205348bc630") } >db.concatenateFieldsDemo.insertOne({"StudentFirstName":"Sam", "StudentLastName":"Williams"}); { "acknowledged" : true, "insertedId" : ObjectId("5cd6ec436d78f205348bc631") }以下是使用find()方法显示集合中所有文档的查询:−> db.concatenateFieldsDemo.find().pretty();这将产生以下输出:{ "_id" : ObjectId("5cd6ebf46d78f205348bc62e"), "StudentFirstName" : "Adam", "StudentLastName" : "Smith" } ... 阅读更多
189 次浏览
首先,让我们创建一个包含文档的集合:−> 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();这将产生以下输出:{ "_id" : ObjectId("5cd9e9f9b50a6c6dd317adb3"), "Scores" : [ ... 阅读更多