开发者

Add extra attribute to data loaded with Mongoimport

开发者 https://www.devze.com 2023-04-01 01:24 出处:网络
In Mongodb, is their a way 开发者_开发技巧to add an extra attribute to documents (--TSV, --headerline) created with mongoimport?

In Mongodb, is their a way 开发者_开发技巧to add an extra attribute to documents (--TSV, --headerline) created with mongoimport?

I don't have control of the data being imported, however I need to be able to distinguish one import data set from another, and their are no attributes in the file to distinguishing one import from another.


I think your best option would be to write your own script to parse the csv/tsv and import it into mongodb. I think it would take under 10 lines of python.

Alternatively if nothing else is inserting into the collection, and your import runs are far enough apart, you could just do something like this between runs:

db.collecton.update({extraField:null}, {$set:{extraField: ObjectId()}}, false, true)

This would work best with an index on {extraField:1}.

0

精彩评论

暂无评论...
验证码 换一张
取 消