Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1457

Cannot marshal nil value for bsoncore.Document

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • None
    • BSON
    • None

    Description

      If I define an object containing a value of type bsoncore.Document such as

      type Example struct {
          DocField bsoncore.Document `bson:"docField"`
      }
      

      and attempt to marshal it when DocField is nil, it will fail with the following error message:

      cannot transform type currentop.Query to a BSON Document: couldn't read length from src, not enough bytes
      

      I can get around the issue by changing the data type to a pointer *bsoncore.Document, but this is very inelegant considering that bsoncore.Document is already nullable. It would be great if this could work as originally written. If not, could we at the very least provide an error message that's indicative of why it's not working?

      Attachments

        Activity

          People

            divjot.arora@mongodb.com Divjot Arora (Inactive)
            david.golub@mongodb.com David Golub
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: