GreenFaith / GreenFaith.github.io

wiki.shixiz.com
1 stars 0 forks source link

Mongo note #12

Open GreenFaith opened 10 years ago

GreenFaith commented 10 years ago

dump 备份数据

mongodump -d database -c collection  

[mongodump manual]

restore 恢复数据

mongorestore --collection people --db accounts dump/accounts/people.bson  

[mongorestore]

GreenFaith commented 10 years ago

Mongo 命令与 SQL 对比 http://docs.mongodb.org/manual/reference/sql-comparison/

GreenFaith commented 10 years ago

类型转换

由于大意,把该存为 整数类型的字段存为字符类型。 在 mongo shell 中转换回来。 记得把错误的源头堵上

db.reply.find().forEach(
  function(x)
  {
    x.topic_id = parseInt(x.topic_id) ;        
    db.reply.save(x);
  }
)
GreenFaith commented 10 years ago

本地数据迁移

ec2 上 8GB SSD 没几天就被 mongodb 吃光。 于是又加载了一块 30 GB 的 SSD,这回应该够用了。

mongod --dpath /mnt/ebs/mongodb

Ubuntu