You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用StormDB执行push操作时触发‘Can't run .value() on non-existant property of non-existant object’错误的解决咨询

解决StormDB中push数组时的"Can't run .value() on non-existant property"错误

这个错误的核心原因是:你链式调用的某个层级对象/属性不存在——要么conversations集合下的id=1条目还没创建,要么路径访问出了问题,导致后续无法对text数组执行push操作。下面是具体的排查和解决步骤:

1. 先验证目标对象是否存在

第一步先确认你要操作的对象到底在不在数据库里:

const targetConversation = db.get('conversations').get(1).value();
console.log(targetConversation);

如果输出是undefined,说明id=1的对话条目根本没被写入数据库,这就是报错的直接原因——你没法往一个不存在的对象的数组里添加元素。

2. 初始化缺失的数据结构

如果目标条目不存在,先把你需要的完整结构写入数据库,再执行push:

// 检查id=1的对话是否存在,不存在就初始化
if (!db.get('conversations').get(1).value()) {
  db.get('conversations').set(1, {
    text: [ "example", "text" ],
    pictures: ["111"],
    chance: { 
      "global": 20, 
      "demotivator": 10, 
      "poll": 10, 
      "mem": 10, 
      "sticker": 10, 
      "bugurt": 10, 
      "anekdot": 10 
    },
    isGold: false
  }).save();
}

// 现在可以安全地往text数组里添加元素了
db.get('conversations').get(1).get("text").push("hello").save();

3. 用defaults简化默认结构设置

如果你不想手动检查对象是否存在,可以用StormDB的defaults方法(需确认你的版本支持该特性),它会自动帮你创建缺失的层级:

db.get('conversations')
  .defaults({
    1: {
      text: [ "example", "text" ],
      pictures: ["111"],
      chance: { 
        "global": 20, 
        "demotivator": 10, 
        "poll": 10, 
        "mem": 10, 
        "sticker": 10, 
        "bugurt": 10, 
        "anekdot": 10 
      },
      isGold: false
    }
  })
  .get(1)
  .get("text")
  .push("hello")
  .save();

4. 最后检查路径拼写

别忘了确认get('conversations')的集合名称、get(1)的id类型(是数字1而非字符串"1")有没有拼写或格式错误,这也是常见的踩坑点。

内容的提问来源于stack exchange,提问作者David

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.30 15:19:10