We need to convert a MongoDB table into VCF file, using python script.
Specifically, we only need to write a couple of fields/columns in the
MongoDB table into VCF file.
However, the record that we retrieve from MongoDB table are in JSON
format. We can only access the "_id" column. We cannot access other
specific columns/fields in order to write them out. We have used
json.dumps(), but it generates string, not records with fields.
We would like to know if there is any way we can access columns/fields
in MongoDB table directly, using python script. Any help is
appreciated.
Thank you very much for your help in advance!
Tiffany
Are you using PyMongo? It returns documents as python dictionaries.
> We would like to know if there is any way we can access columns/fields
> in MongoDB table directly, using python script.
Running under the assumption you aren't using PyMongo:
http://api.mongodb.org/python/current/tutorial.html
> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
I have figured out the problem. The field that I tried to access do
not appear in every record. So I need to put in the check:
for rec in db.table.find():
if ("col_name" in rec):
print json.dump(rec["col_name"])
Thanks a lot for your help!
Tiffany