我将我的报告网站从MySQL转换为使用C#的MongoDB。 到目前为止,我对MongoDB插入数据感到满意。 现在,从收藏中,我需要打印出来。
原创,我的查询就像这样
strSQL = "SELECT " +
" '" + strSearchingStartDate + "' AS SearchStartDate, '" + strSearchingEndDate + "' AS SearchEndDate, '" + strCurrentUserName + "' as WhoPrint, " +
" machinelograwdata.MachineID , " +
" machinelograwdata.Parameter1 AS 'Code', " +
" machinelograwdata.Parameter42 AS 'Orders', " +
" Temp2.HideStartTime AS StartTime, " +
" machinelograwdata.EndTime, " +
" UNIX_TIMESTAMP(machinelograwdata.EndTime) - UNIX_TIMESTAMP(Temp2.HideStartTime) AS Duration, " +
" Temp.StartTime AS CutStartTime, " +
" Temp.EndTime AS CutEndTime, " +
" Temp.Duration AS CutDuration, " +
" NULL AS NestingStartTime, " +
" NULL AS NestingEndTime, " +
" '0.00' AS NestingDuration, " +
" '0.00' AS 'SupplierAream2', " +
" ROUND(machinelograwdata.Parameter3 / 1000000, 2) AS 'GrossAream2', " +
" ROUND(machinelograwdata.Parameter26 / 1000000, 2) AS 'NetAream2', " +
" machinelograwdata.Parameter27 AS 'YieldPercen', " +
" machinelograwdata.Parameter25 AS 'NoPiece', " +
" machinelograwdata.Parameter24 AS 'Material', " +
" machinelograwdata.Parameter44 AS 'Models', " +
" ROUND(machinelograwdata.Parameter9 / 1000000, 2) AS 'Quantity0Area', " +
" '0.00' AS 'Quantity1Area', " +
" '0.00' AS 'Quantity2Area' " +
" FROM " +
" machinelograwdata " +
" INNER JOIN catalogue" +
" ON machinelograwdata.EventID = catalogue.CatalogueID " +
" LEFT JOIN " +
" (SELECT MachineID, Parameter1, EndTime, StartTime, UNIX_TIMESTAMP(EndTime) - UNIX_TIMESTAMP(StartTime) AS Duration " +
" FROM " +
" (SELECT machinelograwdata.MachineID, machinelograwdata.Parameter1, " +
" MAX(machinelograwdata.EndTime) AS EndTime, " +
" MIN(machinelograwdata.StartTime) AS StartTime " +
" FROM " +
" machinelograwdata, catalogue " +
" WHERE " +
" machinelograwdata.EventID = catalogue.CatalogueID " +
" AND catalogue.CatalogueGroup = 'EventDesc' " +
" AND StartTime >= '" + strSearchingStartDate + "' " +
" AND StartTime <= '" + strSearchingEndDate + "' " +
" AND EventID = '15' " +
" AND machinelograwdata.Parameter2 = '0' " +
" GROUP BY machinelograwdata.Parameter1, machinelograwdata.MachineID) M) Temp " +
" ON Temp.Parameter1 = machinelograwdata.Parameter1 " +
" AND Temp.MachineID = machinelograwdata.MachineID " +
" LEFT JOIN " +
" (SELECT MachineID, Parameter1, MIN(StartTime)AS HideStartTime " +
" FROM machinelograwdata " +
" WHERE EventID = '13' " +
" AND machinelograwdata.StartTime <= '" + strSearchingEndDate + "' " +
" AND machinelograwdata.StartTime >= '" + strSearchingStartDate + "' " +
" GROUP BY MachineID, Parameter1) Temp2 " +
" ON Temp2.Parameter1 = machinelograwdata.Parameter1 " +
" AND Temp2.MachineID = machinelograwdata.MachineID " +
" WHERE catalogue.CatalogueGroup = 'EventDesc' " +
" AND machinelograwdata.StartTime <= '" + strSearchingEndDate + "' " +
" AND machinelograwdata.StartTime >= '" + strSearchingStartDate + "' " +
" AND EventID = '14' " +
" AND CONVERT(Parameter35, DECIMAL) <> 0 " +
" ORDER BY machinelograwdata.MachineID , machinelograwdata.StartTime; ";
我的问题是,我可以用MongoDB编写相同的查询吗?
并且在那里&#34;查看&#34; MongoDB上的概念?因为我有使用View的另一个MySQL Report查询。
如果您有任何建议或意见,我将不胜感激。 谢谢, 托马斯
答案 0 :(得分:0)
MongoDB和MySQL是两种截然不同的数据库解决方案。在维护数据方面,两者都遵循不同的方法。 MongoDB是NO SQL数据库意味着存储在其中的数据不与MySQL数据库中的数据模式绑定。
您无法使用SQL查询从MongoDB获取数据。 MongoDB有自己的查询引擎(由Javascript提供支持)来获取数据。
MongoDB不支持视图概念。
由于您可以使用C#从MySQL加载MongoDB中的数据,我建议您检查MongoDB官方C# drivers以查看地图缩减操作。
一种方法是获取内存中的数据,然后构建报告。您可能还会找到一些将SQL查询映射到Mongo的在线解决方案,如this