1

The solution to this RethinkDB query has eluded me for days now. Does not help that I'm a t-SQL developer...

Given a document structure like this:

var messages = {
    "Category A" : { 
                    catName: 'Category A',
                    userInfo: { 
                                userName: 'Hoot',
                                userId: 12345,
                                count: 77
                              }
                     },
    "Category FOO" : { 
                      catName: 'Category FOO',
                      userInfo: { 
                                userName: 'Woot',
                                userId: 67890,
                                count: 42
                              }
                     }

}

where "Category A" and "Category FOO" could be any string entered by a user in the app, basically a dynamic property. This is great for iterating on client side JS using square bracket notation. (messages["Category A"]).

I need to update, using ReQL, the userInfo.count field by "joining" to another table UserMessages on userId field, which exists in both tables.

I've managed to add the result (e.g: "12345":77, "67890": 42 ) as a subdocument to "messages" object using r.forEach() and r.object().

But I must have the result added to the userInfo.

EDIT: To add clarity... I struggle to navigate to the userId if I don't know the Top-level property. ie.:

r.table('messages')('???????????')('userInfo')('userId')

Any suggestions would be greatly appreciated. Thank you.

MojoDBA
  • 118
  • 7
  • Why can't you just `r.forEach` that too? Anyway, dynamic properties are usually not a good DB idea, and here IMO it's especially wrong if it's only to avoid an indexing loop by the client. – Stock Overflaw Oct 17 '16 at 06:58
  • Re-design was the solution to this problem. Thanks. – MojoDBA Feb 28 '17 at 15:31

0 Answers0