【问题标题】:Error in creating index in Mongo db using mongo console使用 mongo 控制台在 Mongo db 中创建索引时出错
【发布时间】:2019-12-16 08:44:51
【问题描述】:

我正在使用这个查询来创建索引:

db.CollectionName.createIndex({result: {$exists:true}, timestamp : {$gte: 1573890921898000}})

我在这里尝试做的是,在时间戳 > 上个月创建索引,并且只为那些存在结果的数据创建索引,但我收到错误

{
    "ok" : 0,
    "errmsg" : "Values in v:2 index key pattern cannot be of type object. Only numbers > 0, numbers < 0, and strings are allowed.",
    "code" : 67,
    "codeName" : "CannotCreateIndex"
}

我在这里做错了什么?

【问题讨论】:

标签: database mongodb indexing


【解决方案1】:

感谢@prasad_ 的建议,我需要使用 partial_Indexes 以便查询变为:

db.CollectionName.createIndex({result: 1, timestamp: 1}, {partialFilterExpression :{result: {$exists:true}, timestamp : {$gte: 1573890921898000}}})

【讨论】:

    猜你喜欢
    • 2016-08-25
    • 1970-01-01
    • 1970-01-01
    • 2020-08-08
    • 1970-01-01
    • 2021-03-14
    • 1970-01-01
    • 2019-03-31
    • 1970-01-01
    相关资源
    最近更新 更多