aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKuzmin Anton <grand.toxa@gmail.com>2025-05-11 17:13:49 +0300
committerGitHub <noreply@github.com>2025-05-11 07:13:49 -0700
commit9c1048bacb66307e456796f328c06670068912b7 (patch)
tree51ac21dd3d5cec4bd705b88f4a21d0d0fcfc368a
parentdddb0f0ae52b06469fb9e2e278af0616ac414f06 (diff)
downloadseaweedfs-9c1048bacb66307e456796f328c06670068912b7.tar.xz
seaweedfs-9c1048bacb66307e456796f328c06670068912b7.zip
Add prefix listing in mongodb_store.go (#6777)
-rw-r--r--weed/filer/mongodb/mongodb_store.go23
1 files changed, 16 insertions, 7 deletions
diff --git a/weed/filer/mongodb/mongodb_store.go b/weed/filer/mongodb/mongodb_store.go
index fbaa464b9..c05ed20f0 100644
--- a/weed/filer/mongodb/mongodb_store.go
+++ b/weed/filer/mongodb/mongodb_store.go
@@ -6,6 +6,7 @@ import (
"crypto/x509"
"fmt"
"os"
+ "regexp"
"time"
"github.com/seaweedfs/seaweedfs/weed/filer"
@@ -229,16 +230,20 @@ func (store *MongodbStore) DeleteFolderChildren(ctx context.Context, fullpath ut
}
func (store *MongodbStore) ListDirectoryPrefixedEntries(ctx context.Context, dirPath util.FullPath, startFileName string, includeStartFile bool, limit int64, prefix string, eachEntryFunc filer.ListEachEntryFunc) (lastFileName string, err error) {
- return lastFileName, filer.ErrUnsupportedListDirectoryPrefixed
-}
+ where := bson.M{
+ "directory": string(dirPath),
+ }
+
+ if len(prefix) > 0 {
+ where["name"].(bson.M)["$regex"] = "^" + regexp.QuoteMeta(prefix)
+ }
-func (store *MongodbStore) ListDirectoryEntries(ctx context.Context, dirPath util.FullPath, startFileName string, includeStartFile bool, limit int64, eachEntryFunc filer.ListEachEntryFunc) (lastFileName string, err error) {
- var where = bson.M{"directory": string(dirPath), "name": bson.M{"$gt": startFileName}}
if includeStartFile {
- where["name"] = bson.M{
- "$gte": startFileName,
- }
+ where["name"].(bson.M)["$gte"] = startFileName
+ } else {
+ where["name"].(bson.M)["$gt"] = startFileName
}
+
optLimit := int64(limit)
opts := &options.FindOptions{Limit: &optLimit, Sort: bson.M{"name": 1}}
cur, err := store.connect.Database(store.database).Collection(store.collectionName).Find(ctx, where, opts)
@@ -276,6 +281,10 @@ func (store *MongodbStore) ListDirectoryEntries(ctx context.Context, dirPath uti
return lastFileName, err
}
+func (store *MongodbStore) ListDirectoryEntries(ctx context.Context, dirPath util.FullPath, startFileName string, includeStartFile bool, limit int64, eachEntryFunc filer.ListEachEntryFunc) (lastFileName string, err error) {
+ return store.ListDirectoryPrefixedEntries(ctx, dirPath, startFileName, includeStartFile, limit, "", eachEntryFunc)
+}
+
func (store *MongodbStore) Shutdown() {
ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
store.connect.Disconnect(ctx)