MongoDB修改資料類型,mongodb資料類型

來源:互聯網
上載者:User

MongoDB修改資料類型,mongodb資料類型

如果類型寫入錯誤,可以通過下面的方式在命令列中修改之。

db.jobtracker_data.find({'collect_time' : { $type : 2 }}).forEach(function(x) {    x.collect_time = parseInt(x.collect_time);    db.jobtracker_data.save(x);})

本來collect_time欄位的值應該是long long,結果不小心變成了string。上面的命令列用$type 為2尋找凡是collect_time值的類型為string的文檔,並傳遞一個JavaScript函數給forEach。

x就是當前一條記錄(doc),之後很簡單,轉型並儲存。


mongodb 類型文檔參考:

http://docs.mongodb.org/manual/reference/operator/query/type/#_S_type


相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.