diff --git a/internal/engine/memory_store.go b/internal/engine/memory_store.go index bcac28e..721483f 100644 --- a/internal/engine/memory_store.go +++ b/internal/engine/memory_store.go @@ -87,11 +87,18 @@ func (ms *MemoryStore) GetCollection(name string) (*Collection, error) { return coll, nil } -// Insert 插入文档到内存 +// Insert 插入文档到内存(集合不存在时自动创建) func (ms *MemoryStore) Insert(collection string, doc types.Document) error { coll, err := ms.GetCollection(collection) if err != nil { - return err + // 集合不存在则创建 + ms.mu.Lock() + ms.collections[collection] = &Collection{ + name: collection, + documents: make(map[string]types.Document), + } + coll = ms.collections[collection] + ms.mu.Unlock() } coll.mu.Lock()