Reputation: 153
I have made a mistake naming subcollection in MongoDB, unfortunately I named them using hyphen :/
Here is sample :
{
id: "..."
"A-Section": {
"val":1
}
}
I need to access the "val" field. Unfortunately hyphens seems to block MongoDB.
So I have to option :
In both case I do not know how to do it and after few researches, I only found answer if the collection name contains hyphen but not a subcollection.
Upvotes: 1
Views: 78
Reputation: 4214
The database contains collections of documents, each document has it's own key-value pairs.
I assume you ment renaming a field in the collection and not an array inside a field.
So you can use the $rename operator to rename all fields in the collection
ex:
db.collectionName.update( {"A-Section": {$exists:true}}, {$rename: {"A-Section": 'ASection'} }, {multi: true} )
Upvotes: 2