1

A Meteor server code tries to insert an object into a Mongo collection. The value of one of the property is a string which contains a dot i.e. ".".

Meteor terminal is complaining :-

Error: key Food 1.1 and drinks must not contain '.'

What does this mean and how to fix it?

 let obj = {
              food: group,
              rest: rule,
              item: item[0],
              key: i
           };

        FoodCol.insert(obj);

edit
The suggested answer by Kishor for replacing the "." with "\uff0E" will produce a space after the dot which is not what a user expects.

Fred J.
  • 5,759
  • 10
  • 57
  • 106
  • It complains about keys, not values. See http://stackoverflow.com/questions/12397118/mongodb-dot-in-key-name – Alex Blex Jun 23 '16 at 09:28

2 Answers2

2

From this link, How to use dot in field name?

You can replace dot symbols of your field name to Unicode equivalent "\uff0E":

Update: As Fred suggested, please use "\u002E" for "."

Community
  • 1
  • 1
Kishor
  • 2,659
  • 4
  • 16
  • 34
  • 1
    One problem with this is that `collection.find` return with a space after the dot that was just coded. Where as the original has no space after the dot. – Fred J. Jun 23 '16 at 09:33
1

We solved this issue by encoding (Base64) the key before insertion and decode after taking out from the db. Since we consume the document as it is and query fields are different and their keys are not encoded.

But if u want to make query using this key or the key should be readable to the user, this solution will be not be suitable.

M. Gopal
  • 404
  • 4
  • 17