diff options
| author | Chris Lu <chrislusf@users.noreply.github.com> | 2025-06-16 14:21:05 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-16 14:21:05 -0700 |
| commit | 5d8a391b956cb981b273e73e41093c679f9a2085 (patch) | |
| tree | a4b1eb8e4196c62a705751a5803a54673826ad69 | |
| parent | 06a314014232373286131d596896c2718217fbf6 (diff) | |
| download | seaweedfs-5d8a391b956cb981b273e73e41093c679f9a2085.tar.xz seaweedfs-5d8a391b956cb981b273e73e41093c679f9a2085.zip | |
filer store: fix nil for mongodb (#6886)
fix https://github.com/seaweedfs/seaweedfs/issues/6885
| -rw-r--r-- | weed/filer/mongodb/mongodb_store.go | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/weed/filer/mongodb/mongodb_store.go b/weed/filer/mongodb/mongodb_store.go index c05ed20f0..3565e5e93 100644 --- a/weed/filer/mongodb/mongodb_store.go +++ b/weed/filer/mongodb/mongodb_store.go @@ -234,16 +234,24 @@ func (store *MongodbStore) ListDirectoryPrefixedEntries(ctx context.Context, dir "directory": string(dirPath), } + nameQuery := bson.M{} + if len(prefix) > 0 { - where["name"].(bson.M)["$regex"] = "^" + regexp.QuoteMeta(prefix) + nameQuery["$regex"] = "^" + regexp.QuoteMeta(prefix) } - if includeStartFile { - where["name"].(bson.M)["$gte"] = startFileName - } else { - where["name"].(bson.M)["$gt"] = startFileName + if len(startFileName) > 0 { + if includeStartFile { + nameQuery["$gte"] = startFileName + } else { + nameQuery["$gt"] = startFileName + } } - + + if len(nameQuery) > 0 { + where["name"] = nameQuery + } + 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) |
