python - Changing the type of a field in a collection in a mongodb database -
the type of field in collection in mongodb database unicode string. field not have data associated in of documents in collection. dont want type string because,i want add subfields python code using pymongo.
the collection has many records in it.so, possible change type of field dictionary in python documents in collection ?
please thank you
i'm not sure mean "the type of field ... string" , "this field ... not have data". mean field exists in documents, set empty string or null
?
in either case, mongodb "schemaless," means won't enforce particular schema on documents, not documents in collection have same structure.
if using framework requires declare schema (mongoengine, mongokit, etc), you'll have make according changes in use of framework, , we'll need know framework you're using.
if you're using pure pymongo, can change document see fit. suppose have document like:
{name: "dcrosta", address: null }
and want make address
sub-document. can in single update:
db.people.update({address: none}, {'$set': {'address': { 'street1': none, 'street2': none, 'city': none, 'state': none, 'zip': none, }}}, multi=true)
(this in pymongo, exact syntax vary little in shell or in other drivers)
Comments
Post a Comment