关于csv数据如何导入mongo的historicialQuotes的命令导入方式

这边提供了两种方式导入这批数据:

第一种,导入批量csv数据到Mongo的historicalQuotes数据表里

1.先删除historicialQuotes的原始数据,可以通过下面的MongoVUE界面里的remove all来实现。关于csv数据如何导入mongo的historicialQuotes的命令导入方式_第1张图片


2. 准备好csv文件格式:

关于csv数据如何导入mongo的historicialQuotes的命令导入方式_第2张图片


3.执行mongoimport文件到mongo数据:


mongoimport -d fcmarketdata -c HistoricalQuotes -type csv -fields TradeDate,OpenPrice,HighPrice,LowPrice,ClosePrice,MatchQuantity,StockCode -file d:\mongodb\data\510050.csv -headerline


这个命令式mongodb\bin里的外部命令

4.进入mongo数据库,切换到fcmarketdata数据库执行下面的改变tradedate和stockcode字段的类型命令


db.HistoricalQuotes.find({'StockCode':510050}).forEach(function(x){
     x.StockCode=x.StockCode+"";
     db.HistoricalQuotes.save(x);
});
db.HistoricalQuotes.find({'StockCode':"510050"}).forEach(function(x){
     x.TradeDate=new Date(x.TradeDate);
     db.HistoricalQuotes.save(x);
});


第二种是直接删除后进行单条插入,这个也是客户要求:


删除时间段里的数据

 db.HistoricalQuotes.remove({"TradeDate":{"$gt":  ISODate("2015-07-08T08:13:49.98Z")}})

插入数据
 db.HistoricalQuotes.insert({"TradeDate" : ISODate("2015-06-23T16:00:00Z"),   "OpenPrice" : 2.89,   "HighPrice" : 2.99,   "LowPrice" : 2.8,   "ClosePrice" : 2.98,   "MatchQuantity" : NumberLong(2573711425),   "StockCode" : "510050"})





 db.HistoricalQuotes.insert({"TradeDate" : ISODate("2015-06-24T16:00:00Z"),   "OpenPrice" : 2.99,   "HighPrice" : 3.03,   "LowPrice" : 2.92,   "ClosePrice" : 3.02,   "MatchQuantity" : NumberLong(2269673751),   "StockCode" : "510050"})






 db.HistoricalQuotes.insert({"TradeDate" : ISODate("2015-06-25T16:00:00Z"),   "OpenPrice" : 3.05,   "HighPrice" : 3.06,   "LowPrice" : 2.91,   "ClosePrice" :2.92,   "MatchQuantity" : NumberLong(2239861306),   "StockCode" : "510050"})




 db.HistoricalQuotes.insert({"TradeDate" : ISODate("2015-06-26T16:00:00Z"),   "OpenPrice" : 2.86,   "HighPrice" : 2.93,   "LowPrice" : 2.63,   "ClosePrice" : 2.69,   "MatchQuantity" : NumberLong(4091997209),   "StockCode" : "510050"})





 db.HistoricalQuotes.insert({"TradeDate" : ISODate("2015-06-29T16:00:00Z"),   "OpenPrice" : 2.77,   "HighPrice" : 2.8,   "LowPrice" : 2.48,   "ClosePrice" : 2.66,   "MatchQuantity" : NumberLong(7737937085),   "StockCode" : "510050"})





 db.HistoricalQuotes.insert({"TradeDate" : ISODate("2015-06-30T16:00:00Z"),   "OpenPrice" : 2.66,   "HighPrice" : 2.86,   "LowPrice" : 2.6,   "ClosePrice" : 2.85,   "MatchQuantity" : NumberLong(6802366362),   "StockCode" : "510050"})





 db.HistoricalQuotes.insert({"TradeDate" : ISODate("2015-07-01T16:00:00Z"),   "OpenPrice" : 2.81,   "HighPrice" : 2.85,   "LowPrice" : 2.69,   "ClosePrice" : 2.73,   "MatchQuantity" : NumberLong(4433403139),   "StockCode" : "510050"})




 db.HistoricalQuotes.insert({"TradeDate" : ISODate("2015-07-02T16:00:00Z"),   "OpenPrice" : 2.79,   "HighPrice" : 2.79,   "LowPrice" : 2.58,   "ClosePrice" : 2.68,   "MatchQuantity" : NumberLong(5865295181),   "StockCode" : "510050"})




 db.HistoricalQuotes.insert({"TradeDate" : ISODate("2015-07-03T16:00:00Z"),   "OpenPrice" : 2.66,   "HighPrice" : 2.73,   "LowPrice" : 2.5,   "ClosePrice" : 2.58,   "MatchQuantity" : NumberLong(4464872090),   "StockCode" : "510050"})





 db.HistoricalQuotes.insert({"TradeDate" : ISODate("2015-07-06T16:00:00Z"),   "OpenPrice" : 2.84,   "HighPrice" : 2.84,   "LowPrice" : 2.63,   "ClosePrice" : 2.74,   "MatchQuantity" : NumberLong(9146831430),   "StockCode" : "510050"})




 db.HistoricalQuotes.insert({"TradeDate" : ISODate("2015-07-07T16:00:00Z"),   "OpenPrice" : 2.68,   "HighPrice" : 2.82,   "LowPrice" : 2.61,   "ClosePrice" : 2.79,   "MatchQuantity" : NumberLong(6650103182),   "StockCode" : "510050"})


 db.HistoricalQuotes.insert({"TradeDate" : ISODate("2015-07-08T16:00:00Z"),   "OpenPrice" : 2.6,   "HighPrice" : 2.76,   "LowPrice" : 2.51,   "ClosePrice" : 2.6,   "MatchQuantity" : NumberLong(7054986215),   "StockCode" : "510050"})



 db.HistoricalQuotes.insert({"TradeDate" : ISODate("2015-07-09T16:00:00Z"),   "OpenPrice" : 2.53,   "HighPrice" : 2.86,   "LowPrice" : 2.48,   "ClosePrice" : 2.79,   "MatchQuantity" : NumberLong(3893441316),   "StockCode" : "510050"})



你可能感兴趣的:(关于csv数据如何导入mongo的historicialQuotes的命令导入方式)