Closed jonlachlan closed 8 years ago
Not sure if context is really any better?
How about "scope"? Such as these roles are valid only within this "scope".
+1 for scope
Let's put it up to vote. I will create comments for each of them, and upvote/downvote those you like/dislike.
group
partition
context
scope
It seems scope has some fans here. :-)
I renamed partition
to scope
. If anyone was using this branch, you will have to rename it in the database. Probably something like from MongoDB shell:
db.users.update({}, {$rename: {'roles.partition': 'roles.scope'}}, {multi: true});
In case someone needs to rename the fields, this is how to do it properly. All credit goes to this Stack Overflow answer
var bulk = db.users.initializeOrderedBulkOp(),
count = 0;
db.users.find({ "roles.partition": { "$exists": true } }).forEach(function(doc) {
doc.roles.forEach(function(role) {
if ( role.hasOwnProperty("partition") ) {
bulk.find({ "_id": doc._id, "roles._id": role._id }).updateOne({
"$set": { "roles.$.scope": role.partition }
});
bulk.find({ "_id": doc._id, "roles._id": role._id }).updateOne({
"$unset": { "roles.$.partition": 1 }
});
count += 2;
if ( count % 500 == 0 ) {
bulk.execute();
bulk = db.users.initializeOrderedBulkOp();
}
}
});
});
if ( count % 500 !== 0 )
bulk.execute();
1.X calls it 'group', 2.X will call it 'partition', but since 2.X is not released yet, why not call it the 'context' instead, which might be more intuitive.