mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
filer: fix mongodb insert
fix https://github.com/chrislusf/seaweedfs/issues/1471
This commit is contained in:
parent
6544e60bea
commit
852e5f7cbc
|
@ -95,6 +95,12 @@ func (store *MongodbStore) RollbackTransaction(ctx context.Context) error {
|
||||||
|
|
||||||
func (store *MongodbStore) InsertEntry(ctx context.Context, entry *filer.Entry) (err error) {
|
func (store *MongodbStore) InsertEntry(ctx context.Context, entry *filer.Entry) (err error) {
|
||||||
|
|
||||||
|
return store.UpdateEntry(ctx, entry)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func (store *MongodbStore) UpdateEntry(ctx context.Context, entry *filer.Entry) (err error) {
|
||||||
|
|
||||||
dir, name := entry.FullPath.DirAndName()
|
dir, name := entry.FullPath.DirAndName()
|
||||||
meta, err := entry.EncodeAttributesAndChunks()
|
meta, err := entry.EncodeAttributesAndChunks()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -107,23 +113,19 @@ func (store *MongodbStore) InsertEntry(ctx context.Context, entry *filer.Entry)
|
||||||
|
|
||||||
c := store.connect.Database(store.database).Collection(store.collectionName)
|
c := store.connect.Database(store.database).Collection(store.collectionName)
|
||||||
|
|
||||||
_, err = c.InsertOne(ctx, Model{
|
opts := options.Update().SetUpsert(true)
|
||||||
Directory: dir,
|
filter := bson.D{{"directory", dir}, {"name", name}}
|
||||||
Name: name,
|
update := bson.D{{"$set", bson.D{{"meta", meta}}}}
|
||||||
Meta: meta,
|
|
||||||
})
|
_, err = c.UpdateOne(ctx, filter, update, opts)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("InsertEntry %st: %v", entry.FullPath, err)
|
return fmt.Errorf("UpdateEntry %s: %v", entry.FullPath, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (store *MongodbStore) UpdateEntry(ctx context.Context, entry *filer.Entry) (err error) {
|
|
||||||
return store.InsertEntry(ctx, entry)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (store *MongodbStore) FindEntry(ctx context.Context, fullpath util.FullPath) (entry *filer.Entry, err error) {
|
func (store *MongodbStore) FindEntry(ctx context.Context, fullpath util.FullPath) (entry *filer.Entry, err error) {
|
||||||
|
|
||||||
dir, name := fullpath.DirAndName()
|
dir, name := fullpath.DirAndName()
|
||||||
|
|
Loading…
Reference in a new issue