2

I'am trying to save the outcome from an JSON API to a MongoDB collection. The JSON data I'am trying to save has the following structure:

compatibility: {
    2.7.1: {
        2.2.6: [
            100,
            1,
            1
        ]
     },
     2.8.3: {
         2.2.6: [
             100,
             2,
             2
         ]
     }
 }

But I'am getting the following error: The dotted field '2.7.1' in 'compatibility.2.7.1' is not valid for storage.

Does anyone know how to fix this?

timouwerkerk
  • 117
  • 1
  • 4
  • 10

1 Answers1

3

You can't have . in field names. Dot is some how special in mongodb. For example if you insert

db.test.insert({
   a: {
      b: 2
   }
});

And then you can search that item with

db.test.find({
   'a.b': 2
});

So imagine you are able to have dot in field name and you insert

db.test.insert({
   a: {
      b: 2
   },
   'a.b': 3
});'

Then it would be strange to search by 'a.b', wouldn't it?

Arūnas Smaliukas
  • 3,231
  • 6
  • 27
  • 46