[GODRIVER-998] Driver should not allow insertion of docs with dots in keys Created: 25/Apr/19  Updated: 10/Jun/20  Resolved: 10/Jun/20

Status: Closed
Project: Go Driver
Component/s: None
Affects Version/s: 1.0.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: David Golden Assignee: Unassigned
Resolution: Won't Fix Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
is depended on by TOOLS-1335 mongoimport imports fields with dots ... Closed
Related
related to SERVER-30575 Please add escaping convention for do... Backlog
related to DRIVERS-308 BSON Key Validation in Drivers Closed

 Description   

The driver allows inserting keys with "." characters, which driver still are not supposed to support.

func main() {
	client, err := mongo.NewClient(options.Client().ApplyURI("mongodb://localhost:27017"))
	if err != nil {
		panic(err)
	}
	ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
	defer cancel()
	err = client.Connect(ctx)
	if err != nil {
		panic(err)
	}
 
	collection := client.Database("test").Collection("dottest")
 
	res, err := collection.InsertOne(context.Background(), bson.M{"hello.world": "world"})
	if err != nil {
		panic(err)
	}
	id := res.InsertedID
	fmt.Println("Inserted", id)
 
	res, err = collection.InsertOne(context.Background(), bson.D{{"hello.world", "world"}})
	if err != nil {
		panic(err)
	}
	id = res.InsertedID
	fmt.Println("Inserted", id)
}

Result:

MongoDB Enterprise > db.dottest.find()
{ "_id" : ObjectId("5cc1a94223fd3159fd7faf96"), "hello.world" : "world" }
{ "_id" : ObjectId("5cc1a94223fd3159fd7faf97"), "hello.world" : "world" }



 Comments   
Comment by Rachelle Palmer [ 10/Jun/20 ]

As we are planning to support dot/dollars in the SERVER, we will not be fixing this issue.

Comment by Kshama Jain [ 18/May/19 ]

I am facing a similar issue while inserting into mongoDB. Following is the error that I am getting:

multiple write errors: [\{write errors: [{Document can't have '.' in field names: a.abc.com/xyz}]}, \{<nil>}].

I want to be able to store keys with dots in it. As, I will never query that part of data. Please help!

MongoDB server version: 3.6.0

Generated at Thu Feb 08 08:35:26 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.