Node Redis-OM:this[#schema].generateId 不是函数

问题描述 投票:0回答:1

大家好,我正在尝试将实体保存到 Redis 存储库中,驱动程序已正确连接,模式创建为与存储库相同的预期。当我尝试保存实体时,问题就出现了,我得到的异常是:

TypeError: this[#schema].generateId is not a function at Repository.save

我已经尝试过使用旧的 redis-om 版本的其他模式类型

Class Session extends Entity {}
但每次都会遇到相同的错误。

redis-node-om
的版本是
0.4.3

这里我提供了不起作用的代码:

中间件.js

const sessionRepository = getSessionRepo(redisClient);
const session = createSessionObj(req);
console.log("[REDIS] **GUARDANDO DATOS EN EL REPOSITORIO DE REDIS**");
const storedSession = await sessionRepository.save(session);

会话架构

const sessionSchema = new Schema(
    "session",
    {
        userId: { type: "string", field: "user_id" },
        role: { type: "string", field: "user_role" },
        jwt: { type: "string", sortable: "yes", field: "user_jwt", weight: 1 },
    },
    { dataStructure: "HASH" }
);

getSessionRepo 函数

function getSessionRepo(redisClient) {
    console.log(sessionSchema);
    const sessionRepository = new Repository(sessionSchema, redisClient);
    console.log(sessionRepository);
    return sessionRepository;
}

createSession函数:

function createSessionObj(req) {
    let session = {};
    session.userId = req.body.userId;
    session.role = req.body.role;
    session.jwt = req.body.tokenJWT;

    return session;
}

编辑:调用 save() 并提供 ID 时

在这种情况下错误有所不同:

'TypeError: Cannot read properties of undefined (reading 'forEach')

javascript node.js redis
1个回答
0
投票

看来根本问题在于

redis-om
库对其内部属性的处理。具体来说,似乎有必要访问
this.#schema.sessionSchema
来调用
generateId()
并使用
forEach
迭代字段。

© www.soinside.com 2019 - 2024. All rights reserved.