mongodb 如何通过递归查询A胜出D的概率和C胜出A的概率

文章 2年前 (2021) admin
0

Q1:mongodb 如何通过递归查询A胜出D的概率和C胜出A的概率?

我们就不能直接多加一个字段,在得到赢值的同时计算概率,存储在这个新的字段中吗?毕竟读操作远比写操作频繁,所以新增加的字段直接计算概率,同时写入win结果,为后续读取节省了更多时间,使得查询速度更快。

Q2:如何启动MongoDB的WEB界面

1:log一定要指定一个xxx.log文件(文件不存在也要这么写,会自动创建,写成这样是不可以的--logpath d:\mongodb\logs)2:serviceName的N字母要大写注意:这条命令要到MongoDB的bin目录下运行,刚开始的时候,我就直接在D:\下运行,结果服务的可执行目录为【"D:\mongod" --logpath "D:\MongoDB\logs\MongoDB.log" --logappend --dbpath "D:\MongoDB\data" --directoryperdb --service 】,肯定是不对的。该命令行指定了日志文件:E:\APMServ5.2.6\MongoDb\logs\MongoDB.log,日志是以追加的方式输出的;数据文件目录:E:\APMServ5.2.6\MongoDb\data,并且参数--directoryperdb说明每个DB都会新建一个目录;Windows服务的名称:MongoDB;以上的三个参数都是可以根据自己的情况而定的,呵呵。最后是安装参数:--install,与之相对的是--remove启动MongoDB:net start MongoDB停止MongoDB:net stop MongoDB删除MongoDB:sc delete MongoDB或运行→regedit→注册表编辑器→HKEY_LOCAL_MACHINE \ SYSTEM \ CurrentControlSet \ Services 下面显示的就是所安装的服务项,删除相应的就好mongod --logpath E:\APMServ5.2.6\MongoDb\logs\MongoDB.log --logappend --dbpath E:\APMServ5.2.6\MongoDb\data --directoryperdb --serviceName MongoDB --install

Q3:mogodb怎么用robomongo导出数据

1.启动Mongodb数据库。在你电脑的E盘和D盘根目录模拟两个Mongodb数据库,分别代表旧库和新库。因为Mongodb的部署非常简单,数据文件分别在E3360 \ MongoDB \ data \ db(使用端口27017)和D3360 \ MongoDB \ data \ db(使用端口27117)下。具体数字。2.连接新库以检查其数据。通过Mongodb自带的客户端RoboMongo-1 . 0 . 0-RC1-Windows-x86 _ 64-496 F5 C2 . zip,解压后找到Robomongo.exe,右键以管理员身份运行。左边显示的界面要求您选择要连接的数据库。3.连接旧库以检查数据。另外,通过客户端,连接旧库。如下图所示,旧数据库包含五条文档数据。让我们通过命令从旧库中导出五条数据。4.从旧库中导出数据。分别导出files.chunks(保存二进制格式的文档数据)和files.files(保存文件信息),分别导出文档数据。5.将数据导入新库中。同样,上一步导出的文件应该单独导入。6.连接新库并检查数据。也可以通过客户端连接到新的库。如下图所示,我们发现已经导入了五条文档数据。

Q4:如何给mongodb管理员权限

1.用户权限描述A. MongoDB没有默认的管理员账号,需要先添加管理员账号,然后启动权限认证。切换到管理数据库,添加的账户就是管理员账户。c .用户只能在创建的用户对应的数据库中完成认证,包括管理员账户。d .管理员可以管理所有数据库,但不能直接管理其他数据库。只有在管理数据库通过身份验证后,他们才能。2.MongoDB数据库角色a .数据库用户角色:读、读、写;b .数据库管理角色:dbAdmin、dbOwner、userAdmin;c .集群管理角色:集群管理员、集群管理器、集群监视器、主机管理器;d .备份和恢复角色:备份和恢复;e .所有数据库角色:readAnyDatabase、readWriteAnyDatabase、userAdminAnyDatabase、DbAdminAnyDatabaseF。超级用户角色:根角色描述:Read:允许用户读取指定的数据库;读写:允许用户读写指定的数据库;dbAdmin:允许用户在指定的数据库中执行管理功能,如索引创建、删除、统计或访问系统. system.profileuserAdmin:允许用户写入系统. users集合,可以在指定的数据库中创建、删除和管理用户。clusterAdmin:仅在Admin数据库中可用,该数据库为用户提供了与碎片和复制集相关的所有功能的管理权限。ReadAnyDatabase:仅在admin数据库中可用,赋予用户所有数据库的读取权限;读写数据库:仅在管理数据库中可用;用户管理数据库:仅在管理数据库中可用。向所有数据库的用户授予用户管理员权限数据库:仅在管理员数据库中可用,并向用户授予所有数据库的数据库管理员权限。Root:仅在管理数据库中可用。超级账号,超级权威3。添加管理员帐户并完成身份验证db.createuser ({user:" root "、PWD3360" zuchezaixian "、角色: [{role:" root "、Db:"admin"}]})注意:数据库中的所有用户都可以在admin: db.system.users.find()配置文件的用户集中进行查询指定启用身份验证并重新启动MongoDB服务。重新启动后,show dbs将提示它未通过身份验证。我们需要切换到admin数据库来完成管理员账号的认证:认证完成后,show dbs就可以成功执行了。4.Spring配置用户身份验证mongodb.properties中指定的管理员帐户和相应的数据库名称在Spring-data-MongoDB 1.7版本之后,您需要在mongo-client中设置credentials属性来指定管理员信息。凭据的配置形式为“用户名:密码@默认数据库”,如凭据=" $ { mongo . user } : $ { mongo . pwd } @ $ { mongo . default dbname。

Q5:如何实现mongodb中的sum汇总操作?

首先在本地机器上安装并设置MongoDB服务。从Mongo网站下载MongoDB,解压到本地目录,比如C:>Mongo在上一个文件夹内创建数据目录。比如:C:\Mongo\Data 如果数据文件存放在其他地方,那么在用mongod.exe命令启动MongoDB时,需要在命令行加参数—-dbpath启动服务 MongoDB提供了两种方式:mongod.exe以后台进程启动;mongo.exe启动命令行界面,可做管理操作。这两个可执行文件都位于Mongo\bin目录下;进入Mongo安装目录的bin目录下,比如:C:> cd Mongo\bin有两种启动方式,如下:mongod.exe –dbpath C:\Mongo\data或者 mongod.exe –config mongodb.configmongodb.config是Mongo\bin目录下的配置文件,需要在此配置文件中指定数据目录(比如,dbpath= C:\Mongo\Data)的位置。连接到MongoDB,到这一步,mongo后台服务已经启动,可以通过http://localhost:27017查看。 MongoDB启动运行后,我们接下来看它的聚合函数。实现聚合函数在关系数据库中,我们可以在数值型字段上执行包含预定义聚合函数的SQL语句,比如,SUM()、COUNT()、MAX()和MIN()。但是在MongoDB中,需要通过MapRece功能来实现聚合以及批处理,它跟SQL里用来实现聚合的GROUP BY从句比较类似。下一节将描述关系数据库中SQL方式实现的聚合和相应的通过MongoDB提供的MapRece实现的聚合。为了讨论这个主题,我们考虑如下所示的Sales表,它以MongoDB中的反范式形式呈现。Sales表#列名数据类型1OrderIdINTEGER2OrderDateSTRING3QuantityINTEGER4SalesAmtDOUBLE5ProfitDOUBLE6CustomerNameSTRING7CitySTRING8StateSTRING9ZipCodeSTRING10RegionSTRING11ProctIdINTEGER12ProctCategorySTRING13ProctSubCategorySTRING14ProctNameSTRING15ShipDateSTRING基于SQL和MapRece的实现我们提供了一个查询的样例集,这些查询使用聚合函数、过滤条件和分组从句,及其等效的MapRece实现,即MongoDB实现SQL中GROUP BY的等效方式。在MongoDB存储的文档上执行聚合操作非常有用,这种方式的一个限制是聚合函数(比如,SUM、AVG、MIN、MAX)需要通过mapper和recer函数来定制化实现。MongoDB没有原生态的用户自定义函数(UDFs)支持。但是它允许使用db.system.js.save命令来创建并保存JavaScript函数,JavaScript函数可以在MapRece中复用。下表是一些常用的聚合函数的实现。稍后,我们会讨论这些函数在MapRece任务中的使用。聚合函数 Javascript 函数SUMdb.system.js.save( { _id : "Sum" ,value : function(key,values){var total = 0;for(var i = 0; i < values.length; i++)total += values[i];return total;}});AVERAGEdb.system.js.save( { _id : "Avg" ,value : function(key,values){var total = Sum(key,values);var mean = total/values.length;return mean;}});MAXdb.system.js.save( { _id : "Max" ,value : function(key,values){var maxValue=values[0];for(var i=1;iMINdb.system.js.save( { _id : "Min" ,value : function(key,values){var minValue=values[0];for(var i=1;iVARIANCEdb.system.js.save( { _id : "Variance" ,value : function(key,values){var squared_Diff = 0;var mean = Avg(key,values);for(var i = 0; i < values.length; i++){var deviation = values[i] - mean;squared_Diff += deviation * deviation;}var variance = squared_Diff/(values.length);return variance;}});STD DEVIATIONdb.system.js.save( { _id : "Standard_Deviation", value : function(key,values){var variance = Variance(key,values);return Math.sqrt(variance);}});SQL和MapRece脚本在四种不同的用例场景中实现聚合函数的代码片段如下表所示。1.各地区的平均订单量下面的查询是用来获取不同地区的平均订单量。SQL QueryMapRece FunctionsSELECTdb.sales.runCommand({maprece : "sales" ,City,State,Region,map:function(){ //emit function handles the group byemit( {//Keycity:this.City,state:this.State,region:this.Region},//Valuesthis.Quantity);},AVG(Quantity)rece:function(key,values){var result = Avg(key, values);return result;}FROM salesGROUP BY City, State, Region//Group By is handled by the emit(keys, values)line in the map() function aboveout : { inline : 1 } });2.产品的分类销售总额下面的查询是用来获取产品的分类销售额,根据产品类别的层级分组。在下面例子中,不同的产品类别作为个体维度,它们也可以被称为更复杂的基于层次的维度。SQL 查询MapRece 函数SELECTdb.sales.runCommand({maprece : "sales" ,ProctCategory, ProctSubCategory, ProctName,map:function(){emit(//Key{key0:this.ProctCategory,key1:this.ProctSubCategory,key2:this.ProctName},//Valuesthis.SalesAmt);},SUM(SalesAmt)rece:function(key,values){var result = Sum(key, values);return result;}FROM salesGROUP BY ProctCategory, ProctSubCategory, ProctName//Group By is handled by the emit(keys, values) line in the map() function aboveout : { inline : 1 } });3. 一种产品的最大利润下面的查询是用来获取一个给定产品基于过滤条件的最大利润。SQL查询MapRece 函数SELECTdb.sales.runCommand({maprece : "sales" ,ProctId, ProctName,map:function(){if(this.ProctId==1)emit( {key0:this.ProctId,key1:this.ProctName},this.Profit);},MAX(SalesAmt)rece:function(key,values){var maxValue=Max(key,values);return maxValue;}FROM salesWHERE ProctId=’1’//WHERE condition implementation is provided in map() functionGROUP BY ProctId, ProctName//Group By is handled by the emit(keys, values) line in the map() function aboveout : { inline : 1 } });4. 总量、总销售额、平均利润这个场景的需求是计算订单的总数、总销售额和平均利润,订单ID在1到10之间,发货时间在2011年的1月1日到12月31日之间。下面的查询是用来执行多个聚合,比如,在指定年份以及指定的不同区域和产品类别范围里订单的总数、总销售额和平均利润。SQL 查询MapRece 函数SELECTdb.sales.runCommand({ maprece : "sales" ,Region,ProctCategory,ProctId,map:function(){emit( {//Keysregion:this.Region,proctCategory:this.ProctCategory,proctid:this.ProctId},//Values{quantSum:this.Quantity,salesSum:this.SalesAmt,avgProfit:this.Profit} );}Sum(Quantity),Sum(Sales),Avg(Profit)rece:function(key,values){var result={quantSum:0,salesSum:0,avgProfit:0};var count = 0;values.forEach(function(value){//Calculation of Sum(Quantity)result.quantSum += values[i].quantSum;//Calculation of Sum(Sales)result.salesSum += values[i].salesSum;result.avgProfit += values[i].avgProfit;count++;}//Calculation of Avg(Profit)result.avgProfit = result.avgProfit /count;return result;},FROM SalesWHEREOrderid between 1 and 10 ANDShipdate BETWEEN ‘01/01/2011’ and‘12/31/2011’query : {"OrderId" : { "$gt" : 1 },"OrderId" : { "$lt" : 10 },"ShipDate" : { "$gt" : "01/01/2011" },"ShipDate" : { "$lt" : "31/12/2011" },},GROUP BYRegion, ProctCategory, ProctId//Group By is handled by the emit(keys, values) line in the map() function aboveLIMIT 3;limit : 3,out : { inline : 1 } });既然我们已经看了在不同业务场景下的聚合函数的代码示例,接下来我们准备来测试这些函数。测试聚合函数MongoDB的MapRece功能通过数据库命令来调用。Map和Rece函数在前面章节里已经使用JavaScript实现。下面是执行MapRece函数的语法。db.runCommand({ maprece : ,map : ,rece : [, query : ][, sort : ][, limit : ][, out : ][, keeptemp: ][, finalize : ][, scope : ][, jsMode : true][, verbose : true]})Where the Output Options include:{ replace : "collectionName" }{ merge : "collectionName"{ rece : "collectionName" }{ inline : 1}

Q6:如何安装,配置MongoDB

在Windows操作系统操作系统上安装蒙古数据库使用本教程在Windows操作系统系统上安装蒙古数据库。平台支持从2.2版本开始,MongoDB不支持Windows XP .请使用较新版本的Windows操作系统来使用较新版本的蒙古数据库.重要信息:如果您正在运行任何版本的视窗服务器2008 R2或Windows 7,请安装一个修补程序来解决Windows操作系统上内存映射文件的问题。安装MongoDB确定您需要哪个MongoDB版本。针对Windows 3360的MongoDB有三个版本针对视窗服务器2008 R2版(即2008年R2)的MongoDB仅在视窗服务器2008 R2版、视窗7 64位版和更新版本的Windows操作系统上运行。此版本利用了Windows操作系统平台的最新增强功能,不能在旧版本的Windows操作系统上运行。适用于Windows 64位的MongoDB运行在比Windows XP更新的任何64位版本的Windows操作系统上,包括视窗服务器2008 R2和Windows 7 64位。适用于Windows 32位的MongoDB运行在比Windows XP新的任何32位版本的Windows操作系统上。32位版本的MongoDB仅用于较旧的系统以及测试和开发系统。32位版本的MongoDB只支持小于2GB的数据库。要查找正在运行的Windows操作系统版本,请在命令提示符下输入以下命令。从MongoDB下载页面下载MongoDB的最新版本。请确保为您的Windows操作系统系统下载了正确版本的蒙古数据库.64位版本的MongoDB不适用于32位的窗户.3安装下载的文件。在窗口资源管理器中,找到下载的MongoDB msi文件,该文件通常位于默认的下载文件夹中。双击中规模集成电路(medium-scale integration的缩写)文件。将出现一组屏幕来指导您完成安装过程。4将MongoDB文件夹移动到另一个位置(可选)。要移动MongoDB文件夹,您必须以管理员身份发出移动命令。例如,要将文件夹移动到C: \ mongodb:Select选择开始菜单所有程序附件。右键单击命令提示符,然后从弹出菜单中选择以管理员身份运行。发出以下命令:光盘\移动c : \ MongoDB-win32-* c : \ MongoDB MongoDB是独立的,没有任何其他系统依赖项。您可以从任何文件夹运行MongoDBer you choose. You may install MongoDB in any folder (e.g. D:\test\mongodb)Run MongoDBWARNINGDo not make mongod.exe visible on public networks without running in “Secure Mode” with the authsetting. MongoDB is designed to be run in trusted environments, and the database does not enable “Secure Mode” by default.1Set up the MongoDB environment.MongoDB requires a data directory to store all data. MongoDB’s default data directory path is\data\db. Create this folder using the following commands from a Command Prompt:md \data\dbYou can specify an alternate path for data files using the --dbpath option to mongod.exe, for example:C:\mongodb\bin\mongod.exe --dbpath d:\test\mongodb\dataIf your path includes spaces, enclose the entire path in double quotes, for example:C:\mongodb\bin\mongod.exe --dbpath "d:\test\mongo db data"2Start MongoDB.To start MongoDB, run mongod.exe. For example, from the Command Prompt:C:\Program Files\MongoDB\bin\mongod.exeThis starts the main MongoDB database process. The waiting for connections message in the console output indicates that the mongod.exe process is running successfully.Depending on the security level of your system, Windows may pop up a Security Alert dialog box about blocking “some features” of C:\Program Files\MongoDB\bin\mongod.exe from communicating on networks. All users should select Private Networks, such as my homeor work network and click Allow access. For additional information on security and MongoDB, please see the Security Documentation.3Connect to MongoDB.To connect to MongoDB through the mongo.exe shell, open another Command Prompt. When connecting, specify the data directory if necessary. This step provides several example connection commands.If your MongoDB installation uses the default data directory, connect without specifying the data directory:C:\mongodb\bin\mongo.exeIf you installation uses a different data directory, specify the directory when connecting, as in this example:C:\mongodb\bin\mongod.exe --dbpath d:\test\mongodb\dataIf your path includes spaces, enclose the entire path in double quotes. For example:C:\mongodb\bin\mongod.exe --dbpath "d:\test\mongo db data"If you want to develop applications using .NET, see the documentation of C# and MongoDB for more information.4Begin using MongoDB.To begin using MongoDB, see Getting Started with MongoDB. Also consider the Proction Notesdocument before deploying MongoDB in a proction environment.Later, to stop MongoDB, press Control+C in the terminal where the mongod instance is running.Configure a Windows Service for MongoDBNOTEThere is a known issue for MongoDB 2.6.0, SERVER-13515, which prevents the use of the instructions in this section. For MongoDB 2.6.0, use Manually Create a Windows Service for MongoDB to create a Windows Service for MongoDB instead.1Configure directories and files.Create a configuration file and a directory path for MongoDB log output (logpath):Create a specific directory for MongoDB log files:md "C:\Program Files\MongoDB\log"In the Command Prompt, create a configuration file for the logpath option for MongoDB:echo logpath=C:\Program Files\MongoDB\log\mongo.log > "C:\Program Files\MongoDB\mongod.cfg"2Run the MongoDB service.Run all of the following commands in Command Prompt with “Administrative Privileges:”Install the MongoDB service. For --install to succeed, you must specify the logpath run-time option."C:\Program Files\MongoDB\bin\mongod.exe" --config "C:\Program Files\MongoDB\mongod.cfg" --installModify the path to the mongod.cfg file as needed.To use an alternate dbpath, specify the path in the configuration file (e.g. C:\ProgramFiles\MongoDB\mongod.cfg) or on the command line with the --dbpath option.If the dbpath directory does not exist, mongod.exe will not start. The default value for dbpath is\data\db.If needed, you can install services for multiple instances of mongod.exe or mongos.exe. Install each service with a unique --serviceName and --serviceDisplayName. Use multiple instances only when sufficient system resources exist and your system design requires it.3Stop or remove the MongoDB service as needed.To stop the MongoDB service use the following command:net stop MongoDBTo remove the MongoDB service use the following command:"C:\Program Files\MongoDB\bin\mongod.exe" --removeManually Create a Windows Service for MongoDBThe following procere assumes you have installed MongoDB using the MSI installer, with the default path C:\Program Files\MongoDB 2.6 Standard.If you have installed in an alternative directory, you will need to adjust the paths as appropriate.1Open an Administrator command prompt.Windows 7 /Vista /Server 2008 (and R2)Press Win + R, then type cmd, then press Ctrl + Shift + Enter.Windows 8Press Win + X, then press A.Execute the remaining steps from the Administrator command prompt.2Create directories.Create directories for your database and log files:mkdir c:\data\dbmkdir c:\data\log3Create a configuration file.Create a configuration file. This file can include any of the configuration options for mongod, butmust include a valid setting for logpath:The following creates a configuration file, specifying both the logpath and the dbpath settings in the configuration file:echo logpath=c:\data\log\mongod.log> "C:\Program Files\MongoDB 2.6 Standard\mongod.cfg"echo dbpath=c:\data\db>> "C:\Program Files\MongoDB 2.6 Standard\mongod.cfg"4Create the MongoDB service.Create the MongoDB service.sc.exe create MongoDB binPath= "\"C:\Program Files\MongoDB 2.6 Standard\bin\mongod.exe\" --service --config=\"C:\Program Files\MongoDB 2.6 Standard\mongod.cfg\"" DisplayName= "MongoDB 2.6 Standard" start= "auto"sc.exe requires a space between “=” and the configuration values (eg “binPath= ”), and a “” to escape double quotes.If successfully created, the following log message will display:[SC] CreateService SUCCESS5Start the MongoDB service.net start MongoDB6Stop or remove the MongoDB service as needed.To stop the MongoDB service, use the following command:net stop MongoDBTo remove the MongoDB service, first stop the service and then run the following command:sc.exe delete MongoDB

版权声明:admin 发表于 2021年11月9日 上午8:29。
转载请注明:mongodb 如何通过递归查询A胜出D的概率和C胜出A的概率 | 热豆腐网址之家

相关文章