diff --git a/server/backend/database/mongo/client.go b/server/backend/database/mongo/client.go index 69c429e46..e5b0db867 100644 --- a/server/backend/database/mongo/client.go +++ b/server/backend/database/mongo/client.go @@ -769,6 +769,9 @@ func (c *Client) FindDocInfosByKeys( projectID types.ID, docKeys []key.Key, ) ([]*database.DocInfo, error) { + if len(docKeys) == 0 { + return nil, nil + } filter := bson.M{ "project_id": projectID, "key": bson.M{ diff --git a/server/backend/database/testcases/testcases.go b/server/backend/database/testcases/testcases.go index da3919471..9bd173d72 100644 --- a/server/backend/database/testcases/testcases.go +++ b/server/backend/database/testcases/testcases.go @@ -127,6 +127,27 @@ func RunFindDocInfosByKeysTest( assert.Len(t, infos, len(docKeys)) }) + t.Run("find docInfos by empty key slice test", func(t *testing.T) { + ctx := context.Background() + clientInfo, err := db.ActivateClient(ctx, projectID, t.Name()) + assert.NoError(t, err) + + // 01. Create documents + docKeys := []key.Key{ + "test", "test$3", "test123", "test$0", + "search$test", "abcde", "test abc", + } + for _, docKey := range docKeys { + _, err := db.FindDocInfoByKeyAndOwner(ctx, clientInfo.RefKey(), docKey, true) + assert.NoError(t, err) + } + + // 02. Find documents + infos, err := db.FindDocInfosByKeys(ctx, projectID, []key.Key{}) + assert.NoError(t, err) + assert.Len(t, infos, 0) + }) + t.Run("find docInfos by keys where some keys are not found test", func(t *testing.T) { ctx := context.Background() clientInfo, err := db.ActivateClient(ctx, projectID, t.Name())