x***@126.com
x***@126.com
  • 发布:2025-02-26 23:13
  • 更新:2025-02-28 14:44
  • 阅读:108

【报Bug】数据库schema是date类型 查询时提示 右值类型不正确

分类:uniCloud

产品分类: uniCloud/支付宝小程序云

操作步骤:

schema:

{  
    "bsonType": "object",  
    "properties": {  
        "startDate": {  
            "bsonType": "date",  
            "description": "开始时间"  
        }  
    }  
}

JQL

const dbCmd = db.command  
const $ = dbCmd.aggregate  
// db.collection('date-test').add({  
//  startDate: new Date()  
// })  

db.collection('date-test').where({  
    startDate: dbCmd.lte(new Date())  
}).get()

预期结果:

查询结果

实际结果:

报错 右侧值类型不正确

bug描述:

schema:

{  
    "bsonType": "object",  
    "properties": {  
        "startDate": {  
            "bsonType": "date",  
            "description": "开始时间"  
        }  
    }  
}

JQL

const dbCmd = db.command  
const $ = dbCmd.aggregate  
// db.collection('date-test').add({  
//  startDate: new Date()  
// })  

db.collection('date-test').where({  
    startDate: dbCmd.lte(new Date())  
}).get()

提示<=类型不正确

查询时用时间戳不报错但是搜不出来

用getTemp 再联表查是正常的

2025-02-26 23:13 负责人:无 分享
已邀请:
x***@126.com

x***@126.com (作者)

不会要倒闭吧,所有问题都石沉大海呢。。

DCloud_uniCloud_VK

DCloud_uniCloud_VK

时间字段的类型 bsonType 应该是 timestamp 代表时间戳, 不建议用 Date 类型, 数据库大于等于的判断作用于数值(number)类型 timestamp 本质就是number, 和string类型(按ASCII码大小比)

  • x***@126.com (作者)

    感谢解答,但是我看文档 https://doc.dcloud.net.cn/uniCloud/cf-database-dbcmd.html#dbcmd-compare 里说date可以用来比较呢

    2025-03-01 21:03

  • x***@126.com (作者)

    而且getTemp 是不报错的,联表查询也正常

    2025-03-01 21:04

  • DCloud_uniCloud_VK

    回复 x***@126.com: 建议用时间戳,因为date有时区问题,特别是在阿里云和腾讯云那是0时区的

    2025-03-03 11:23

要回复问题请先登录注册