Skip to content

Field names with dots can be inserted if the field is > 1 level deep in array #193

@Zelfapp

Description

@Zelfapp

Not sure if the library is at fault or ext-mongodb 1.1.7, but field names with dots should generate a MongoException regardless of depth of array in which they are found, since mongo 3.x no longer allows dots in field names.

This issue was identified when we attempted to incorrectly insert documents with dots in field names.

For example, this will insert into mongo 3.x:

$data = [
    "abc" => [
        "Leather.CPO.Nametag" => 1   
    ]
];

$collection->insertOne($data);

{
    "_id" : ObjectId("57589f59ae8c50f34f8b4567"),
    "abc" : {
        "Leather.CPO.Nametag" : NumberLong(1)
    }
}

If the array is 1 level, then insert like below will fail properly:

$data = [
     "Leather.CPO.Nametag" => 1
];

$collection->insertOne($data);

PHP Fatal error:  Uncaught exception 'MongoException' with message ''.' not allowed in key: Leather.CPO.Nametag' in -:12

Attempting shell insert when > 1 level deep does fail correctly though:

db.ezrshop_builders.insert(
... {
...     "abc" :
...         {
...             "Leather.CPO.Nametag":1
...         }
... }
... )
2016-06-08T15:46:02.984-0700 E QUERY    Error: can't have . in field names [Leather.CPO.Nametag]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions