0

I have an array of documents as such:

"players" : [
    {
        "approved" : true,
        "isGM" : true,
        "user" : {
            "userID" : 1,
            "username" : "User 1"
        }
    }
],

I'm trying to rename userID to userId with

db.games.update({}, { $rename: { 'players.user.userID': 'players.user.userId' } });

But when I do, I get cannot use the part (players of players.user.userID) to traverse the element. How can I rename these fields and why the current method doesn't work?

halfer
  • 19,824
  • 17
  • 99
  • 186
Rohit
  • 3,018
  • 2
  • 29
  • 58
  • `"players"` is an array. At present you need to match each element of the array individually and issue the rename. Just the same as any update, all the techniques are outlined on the linked duplicate. – Neil Lunn Sep 20 '17 at 23:03
  • I apologize for the dup. I did search before asking, but didn't find an answer I thought matched. I can see where my logic was wrong. Sorry. – Rohit Sep 20 '17 at 23:06

0 Answers0