MongoBaseStore
public class MongoBaseStore implements BaseStore
io/agentscope/extensions/mongodb/store/MongoBaseStore.java:57–321Mongo 基类存储,负责持久化与读取数据。位于 io.agentscope.extensions.mongodb.store 包,实现 BaseStore。核心成员包括 get、put、putIfVersion、search、delete、MongoBaseStore。
MongoDB-backed implementation of BaseStore.
Each item is stored as a separate MongoDB document. Namespace paths and keys are encoded
into a compound _id for uniqueness, using \\u001F (ASCII Unit Separator) as
the segment delimiter. The namespace field stores the full namespace path with a
trailing separator, enabling prefix-matching via range queries ($gte/{$lt}) on the
compound index — consistent with PostgresBaseStore and JdbcStore.
Supports optimistic concurrency via a version field. Value serialization uses
JsonCodec#convertValue to avoid an intermediate JSON string round-trip.
构造器摘要Constructor Summary
| 构造器Constructor | 说明Description |
|---|---|
public MongoBaseStore(MongoDatabase database, String collectionName) | 创建新的实例使用共享`JsonUtils#getJsonCodec()`。 Creates a new instance using the shared `JsonUtils#getJsonCodec()`. |
public MongoBaseStore(MongoDatabase database, String collectionName, JsonCodec codec) | 创建新的实例使用自定义`JsonCodec`。 Creates a new instance with a custom `JsonCodec`. |
方法摘要Method Summary
| 方法Method | 说明Description |
|---|---|
public StoreItem get(List<String> namespace, String key) | 按条件读取数据。 Performs the get operation. |
public void put(List<String> namespace, String key, Map<String, Object> value) | 执行 `put` 方法。 Performs the put operation. |
public boolean putIfVersion(List<String> namespace, String key, Map<String, Object> value, long expectedVersion) | 执行 `putIfVersion` 方法。 Performs the put if version operation. |
public List<StoreItem> search(List<String> namespace, int limit, int offset) | 执行搜索相关操作。 Searches for items within a namespace, including child namespaces (prefix matching). |
public void delete(List<String> namespace, String key) | 删除数据。 Performs the delete operation. |
构造器详情Constructor Detail
MongoBaseStore
public MongoBaseStore(MongoDatabase database, String collectionName)
创建新的实例使用共享JsonUtils#getJsonCodec()。
Creates a new instance using the shared JsonUtils#getJsonCodec().
| 名称Name | 类型Type | 说明Description |
|---|---|---|
database | MongoDatabase | MongoDB 数据库。the MongoDB database |
collectionName | String | 集合名称。the collection name |
io/agentscope/extensions/mongodb/store/MongoBaseStore.java:78–80MongoBaseStore
public MongoBaseStore(MongoDatabase database, String collectionName, JsonCodec codec)
创建新的实例使用自定义JsonCodec。
Creates a new instance with a custom JsonCodec.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
database | MongoDatabase | MongoDB 数据库。the MongoDB database |
collectionName | String | 集合名称。the collection name |
codec | JsonCodec | 编解码器(类型 `JsonCodec`)。JSON codec for serializing values |
io/agentscope/extensions/mongodb/store/MongoBaseStore.java:89–95方法详情Method Detail
get
public StoreItem get(List<String> namespace, String key)
按条件读取数据。
Performs the get operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
namespace | List<String> | 命名空间(类型 `List`)。The namespace. |
key | String | 键(类型 `String`)。The key. |
StoreItemio/agentscope/extensions/mongodb/store/MongoBaseStore.java:97–112put
public void put(List<String> namespace, String key, Map<String, Object> value)
执行 put 方法。
Performs the put operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
namespace | List<String> | 命名空间(类型 `List`)。The namespace. |
key | String | 键(类型 `String`)。The key. |
value | Map<String, Object> | 值(类型 `Map`)。The value. |
io/agentscope/extensions/mongodb/store/MongoBaseStore.java:114–147putIfVersion
public boolean putIfVersion(List<String> namespace, String key, Map<String, Object> value, long expectedVersion)
执行 putIfVersion 方法。
Performs the put if version operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
namespace | List<String> | 命名空间(类型 `List`)。The namespace. |
key | String | 键(类型 `String`)。The key. |
value | Map<String, Object> | 值(类型 `Map`)。The value. |
expectedVersion | long | expected 版本(类型 `long`)。The expected version. |
booleanio/agentscope/extensions/mongodb/store/MongoBaseStore.java:149–195search
public List<StoreItem> search(List<String> namespace, int limit, int offset)
执行搜索相关操作。
Searches for items within a namespace, including child namespaces (prefix matching).
| 名称Name | 类型Type | 说明Description |
|---|---|---|
namespace | List<String> | 命名空间(类型 `List`)。The namespace. |
limit | int | 数量上限(类型 `int`)。The limit. |
offset | int | 偏移量(类型 `int`)。The offset. |
List<StoreItem>io/agentscope/extensions/mongodb/store/MongoBaseStore.java:211–237delete
public void delete(List<String> namespace, String key)
删除数据。
Performs the delete operation.
| 名称Name | 类型Type | 说明Description |
|---|---|---|
namespace | List<String> | 命名空间(类型 `List`)。The namespace. |
key | String | 键(类型 `String`)。The key. |
io/agentscope/extensions/mongodb/store/MongoBaseStore.java:239–244