diff --git a/pkg/storage/mongodb/ldstore/context_store.go b/pkg/storage/mongodb/ldstore/context_store.go index 68d17e44a..570c77db0 100644 --- a/pkg/storage/mongodb/ldstore/context_store.go +++ b/pkg/storage/mongodb/ldstore/context_store.go @@ -19,6 +19,7 @@ import ( ldcontext "github.com/trustbloc/did-go/doc/ld/context" ldstore "github.com/trustbloc/did-go/doc/ld/store" "github.com/trustbloc/kms-go/spi/storage" + "github.com/trustbloc/vcs/pkg/storage/mongodb/internal" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" @@ -212,7 +213,6 @@ func (s *ContextStore) Import(documents []ldcontext.Document) error { for _, doc := range targetDocs { _, err := collection.InsertOne(ctxWithTimeout, doc.bsonDoc) - if err != nil { if mongo.IsDuplicateKeyError(err) { s.cache.Add(doc.remoteDoc.ContextURL, doc.remoteDoc) @@ -317,9 +317,14 @@ func getJSONLDRemoteDocumentBytes(d ldcontext.Document) ([]byte, error) { return nil, fmt.Errorf("document from reader: %w", err) } + mongoDoc, err := internal.PrepareDataForBSONStorage(content) + if err != nil { + return nil, fmt.Errorf("prepare data for bson storage: %w", err) + } + rd := &jsonld.RemoteDocument{ DocumentURL: d.DocumentURL, - Document: content, + Document: mongoDoc, ContextURL: d.URL, } @@ -337,6 +342,11 @@ func mapToBSONRemoteDocument(rd *jsonld.RemoteDocument) (*bsonRemoteDocument, er return nil, err } + content, err = internal.PrepareDataForBSONStorage(content) + if err != nil { + return nil, err + } + return &bsonRemoteDocument{ DocumentURL: rd.DocumentURL, Document: content, diff --git a/pkg/storage/mongodb/ldstore/context_store_test.go b/pkg/storage/mongodb/ldstore/context_store_test.go index 7a2b3e5e0..d89d62c05 100644 --- a/pkg/storage/mongodb/ldstore/context_store_test.go +++ b/pkg/storage/mongodb/ldstore/context_store_test.go @@ -43,6 +43,9 @@ const ( "homepage": { "@id": "http://xmlns.com/foaf/0.1/homepage", "@type": "@id" + }, + "...": { + "@id": "https://www.iana.org/assignments/jwt#..." } } }`