Class MongoBaseStore

java.lang.Object
io.agentscope.extensions.mongodb.store.MongoBaseStore
All Implemented Interfaces:
io.agentscope.harness.agent.filesystem.remote.store.BaseStore

public class MongoBaseStore extends Object implements io.agentscope.harness.agent.filesystem.remote.store.BaseStore
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(java.lang.Object, java.lang.Class<T>) to avoid an intermediate JSON string round-trip.

  • Constructor Details

    • MongoBaseStore

      public MongoBaseStore(com.mongodb.client.MongoDatabase database, String collectionName)
      Creates a new instance using the shared JsonUtils.getJsonCodec().
      Parameters:
      database - the MongoDB database
      collectionName - the collection name
    • MongoBaseStore

      public MongoBaseStore(com.mongodb.client.MongoDatabase database, String collectionName, io.agentscope.core.util.JsonCodec codec)
      Creates a new instance with a custom JsonCodec.
      Parameters:
      database - the MongoDB database
      collectionName - the collection name
      codec - JSON codec for serializing values
  • Method Details

    • get

      public io.agentscope.harness.agent.filesystem.remote.store.StoreItem get(List<String> namespace, String key)
      Specified by:
      get in interface io.agentscope.harness.agent.filesystem.remote.store.BaseStore
    • put

      public void put(List<String> namespace, String key, Map<String,Object> value)
      Specified by:
      put in interface io.agentscope.harness.agent.filesystem.remote.store.BaseStore
    • putIfVersion

      public boolean putIfVersion(List<String> namespace, String key, Map<String,Object> value, long expectedVersion)
      Specified by:
      putIfVersion in interface io.agentscope.harness.agent.filesystem.remote.store.BaseStore
    • search

      public List<io.agentscope.harness.agent.filesystem.remote.store.StoreItem> search(List<String> namespace, int limit, int offset)
      Searches for items within a namespace, including child namespaces (prefix matching).

      The namespace path is encoded with a trailing separator so that a range query gte(nsPrefix) / lt(nsPrefix + ￿) matches both the exact namespace and all descendant sub-namespaces, consistent with InMemoryStore, PostgresBaseStore, and JdbcStore.

      Note: the upper bound uses Character.MAX_VALUE (￿), which does not match namespace segments containing Unicode supplementary characters (code points above U+FFFF, such as emoji). This is a theoretical limitation — supplementary characters are unlikely in namespace segments — and the range query preserves full B-tree index utilisation, which a $regex prefix match would not.

      Specified by:
      search in interface io.agentscope.harness.agent.filesystem.remote.store.BaseStore
    • delete

      public void delete(List<String> namespace, String key)
      Specified by:
      delete in interface io.agentscope.harness.agent.filesystem.remote.store.BaseStore