0

I'm looking for advise on what I'm doing wrong or what I should be doing to Tag a sharded collection in MongoDB, which has a shard key on a sub-document field.

I'm using MongoDB 2.4 and My User collection structure looks like the blow, and is keyed on AccountId:

  • First Name
  • Last Name
  • Account (sub-document)
    • AccountId <-- shard key
    • Field X
    • Field Y-
    • ...and so on

If call the addTagRange() helper like so:

sh.addTagRange("Mydb.User", {"Account.AccountId":MinKey}, {"Account.AccountId":MaxKey}, "ssd")

The error i get is:

JavaScript execution failed: can't have . in field names [Account.AccountId] at src/mongo/shell/collection.js:L143

I've tried removing quotes but that gives a similar error:

JavaScript execution failed: SyntaxError: Unexpected token .

So i'm wondering now is this possible via the helper, or do I have to edit the config db to make this work. I would have thought this was possible as MongoDB allows a shard key to be created on a sub-document in the first place.

Any help is appreciated.

Thanks

nathanw
  • 13
  • 1
  • 3

1 Answers1

0

You could use \uff0e to instead of dot

sh.addTagRange("Mydb.User", {"Account\uff0eAccountId":MinKey}, {"Account\uff0eAccountId":MaxKey}, "ssd")

see more: http://docs.mongodb.org/manual/faq/developers/#faq-dollar-sign-escaping

How to use dot in field name?

Community
  • 1
  • 1