[GODRIVER-1501] Incorrect parsing of extended JSON $dbPointer Created: 29/Feb/20  Updated: 30/Mar/22

Status: Backlog
Project: Go Driver
Component/s: JSON & ExtJSON
Affects Version/s: 1.3.0
Fix Version/s: None

Type: Bug Priority: Minor - P4
Reporter: David Golden Assignee: Unassigned
Resolution: Unresolved Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Epic Link: Improve JSON & ExtJSON Implementation

 Description   

The driver parses a string $id field, but per the spec, this must be an object ID, not a string.

Repro:

package main
 
import (
	"encoding/hex"
	"fmt"
	"log"
 
	"go.mongodb.org/mongo-driver/bson"
)
 
func main() {
	input := `{"":{"$dbPointer":{"$ref":"","$id":"000000000000000000000000"}}}`
 
	var output bson.Raw
	err := bson.UnmarshalExtJSON([]byte(input), false, &output)
	if err != nil {
		log.Fatal(err)
	}
 
	fmt.Println(hex.EncodeToString(output))
}

Output:

180000000c00010000000000000000000000000000000000


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