c# MongoDB relationships: problem with relation one to many reference

Viewed 62

I'm new to MongoDb

i have a class Book that has many AuthorsId. and i want to store the ObjectId List in the collection but i get error when call Book.insertOne(book). The error is "The JSON value could not be converted to MongoDB.Bson.ObjectId. Path: $.authorsId[0] | LineNumber: 6 | BytePositionInLine: 35.""

 public class Book
    {
        [BsonId]
        [BsonRepresentation(MongoDB.Bson.BsonType.ObjectId)]
        public string Id { get; set; }

        [BsonElement("Title")]
        public string Title{ get; set; }
      

        [BsonElement("DatePublicacion")]
        public DateTime? DatePublication { get; set; }

        [BsonElement("AuthorsId")
         public List<ObjectId> AuthorsId{ get; set; }
          
    }

i call from postman in this way:

{ "Title":"Book1", "DatePublication":"2020-05-20", "authorsId":[ "618acaf4b43af2fa1dc4d69b" ]

thanks

0 Answers
Related