wxb-bizhi-classify.schema.json
{
"bsonType": "object",
"required": [
"name"
],
"permission": {
"read": true,
"create": false,
"update": false,
"delete": false
},
"properties": {
"_id": {
"description": "存储文档 ID,系统自动生成"
},
"name": {
"bsonType": "string",
"description": "分类名称",
"label": "名称",
"trim": "both",
"minLength": 2,
"maxLength": 8
},
"select": {
"bsonType": "bool",
"description": "是否精选 默认false ,true是精选",
"defaultValue":false
},
"enable": {
"bsonType": "bool",
"description": "是否启用 默认false ,true是启用",
"defaultValue":false
},
"sort": {
"bsonType": "int",
"description": "类别显示顺序",
"label": "排序"
},
"picurl": {
"bsonType": "string",
"description": "缩略图地址"
},
"createTime": {
"bsonType": "timestamp",
"description": "创建时间",
"forceDefaultValue": {
"$env": "now"
}
}
},
"version": "0.0.1"
}
wxb-bizhi-piclist.schema.json
{
"bsonType": "object",
"required": [
"user_id",
"title",
"content"
],
"permission": {
"read": true,
"create": true,
"update": true,
"delete": true
},
"properties": {
"_id": {
"description": "存储文档 ID(用户 ID),系统自动生成"
},
"user_id": {
"bsonType": "string",
"description": "作者ID, 参考`uni-id-users` 表",
"foreignKey": "uni-id-users._id",
"defaultValue": {
"$env": "uid"
}
},
"classid": {
"bsonType": "string",
"title": "分类",
"description": "分类 id,参考`wxb-bizhi-classify`表",
"foreignKey": "wxb-bizhi-classify._id"
},
"description":{
"bsonType": "string",
"description": "描述",
"defaultValue":""
},
"score":{
"bsonType": "string",
"description": "评分"
},
"tabs": {
"bsonType": "array",
"description": "标签组",
"defaultValue":[]
},
"checked": {
"bsonType": "bool",
"description": "是否展现:true展现 false不展现",
"defaultValue": true
},
"view_count": {
"bsonType": "int",
"title": "阅读次量",
"description": "阅读次量",
"defaultValue":50
},
"download_count": {
"bsonType": "int",
"description": "下载次数",
"defaultValue":0
},
"score_count": {
"bsonType": "int",
"description": "评分数量",
"defaultValue":0
},
"createTime": {
"bsonType": "timestamp",
"title": "发表时间",
"description": "发表时间",
"defaultValue": {
"$env": "now"
}
},
"picurl": {
"bsonType": "string",
"description": "壁纸地址"
}
},
"version": "0.0.1"
}
云对象
client-bizhi-classify 下的index.obj.js
module.exports = {
_before: function () { // 通用预处理器
},
async list({pageSize=9,pageNum=1}={}){
let skip=(pageNum-1)*pageSize
let wer={enable:true}
const dbJQL=uniCloud.databaseForJQL({
clientInfo:this.getClientInfo()
})
let classTemp= dbJQL.collection("wxb-bizhi-classify")
.where(wer)
.orderBy("sort asc")
.skip(skip).limit(pageSize)
.getTemp()
// return classTemp
let picTemp= dbJQL.collection("wxb-bizhi-piclist")
.where("classid == wxb-bizhi-classify._id")
.field("createTime,classid")
.orderBy("createTime desc")
.limit(1).getTemp()
return await dbJQL.collection(classTemp,picTemp).get()
}
}
运行结果
16:17:32.230 [本地运行:支付宝云:xxmwallwaper-cound]本地运行云对象【client-bizhi-classify】...
16:17:33.774 [本地运行]TypeError: Cannot read properties of null (reading '_id')
16:17:33.774 [本地运行] at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
16:17:34.043 [本地运行]Error: Cannot read properties of null (reading '_id')
16:17:34.043 [本地运行] at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
16:17:34.043 [本地运行] at async ce.list (F:\hbuiidler\xiaobin\霄缤壁纸-后台管理\uniCloud-alipay\cloudfunctions\client-bizhi-classify\index.obj.js:23:10)
16:17:34.043 [本地运行] at async D:\DevelopmentTools\HBuilderX.4.87.2025121004\HBuilderX\plugins\unicloud\alipay\index.js:1:19177
1 个回复
Ask小助手 - Ask社区AI助手
你遇到的
TypeError: Cannot read properties of null (reading '_id')是因为 支付宝云新空间(2024年11月后创建) 的 内置数据库 存在 语法兼容性问题,导致 JQL 联表查询(虚拟联表) 无法正确处理foreignKey关联。✅ 问题原因(来自知识库)
✅ 解决方案(来自知识库)
方案1:改用扩展数据库(推荐)
方案2:避免虚拟联表,改用传统查询
如果暂时无法迁移到扩展数据库,可以 放弃
getTemp()联表查询,改用 分步查询:❌ 不兼容的写法(当前代码)
✅ 总结
建议 优先迁移到扩展数据库,彻底解决兼容性问题。
要回复问题请先登录或注册
公告
更多>相关问题