代码之家  ›  专栏  ›  技术社区  ›  AdamG

领域:在使用服务器同步领域时,是否可以存在本地领域?

  •  1
  • AdamG  · 技术社区  · 9 年前

    我有一个服务器同步的领域,这是工作良好。我想添加一个传统的本地域,只在本地存储一些项目:

      this.userRealm = new Realm({
        path: 'userRealm.realm',
        schema: [cgps_schema.DirectoryFavoritesSchema],
      });
    

    1 回复  |  直到 9 年前
        1
  •  1
  •   Constantin S. Pan    9 年前

    你应该使用不同的 path

    const Realm = require('realm');
    
    const ItemSchema = {name: 'Item', properties: {id: 'int', name: 'string'}};
    
    const unsynced = new Realm({
        path: 'unsynced.realm',
        schema: [ItemSchema],
    })
    
    Realm.Sync.User.register('http://localhost:9080', 'user1', 'pass1', (error, user) => {
        const synced = new Realm({
            path: 'synced.realm',
            schema: [ItemSchema],
            sync: {
                url: 'realm://localhost:9080/~/synced',
                user: user,
            },
        })
        synced.close();
        user.logout();
        unsynced.close();
    })
    
    推荐文章