Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MOOOWOOO/517b061e1665246e6431ab728d741837 to your computer and use it in GitHub Desktop.
Save MOOOWOOO/517b061e1665246e6431ab728d741837 to your computer and use it in GitHub Desktop.
更新mongodb一个集合的某个字段的类型
db.getCollection('years3').find().forEach(function(doc) {
var a = String(doc.date);
var d = new Date(a.substr(0,4)+'/'+a.substr(4,2)+'/'+a.substr(6,2));
db.getCollection('years3').update( {_id: doc._id}, {$set: {date: d}});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment