【问题标题】:Can we use of Nested where clause in sails js Collection我们可以在sails js Collection中使用嵌套的where子句吗
【发布时间】:2018-05-05 02:57:45
【问题描述】:

我正在尝试以下查询以获取 start_date 大于当前日期的输出。

这些在我的收藏结构中:

{ 
    "_id" : ObjectId("5aeac6cd1b7e6f252832ca0e"), 
    "recruiter_id" : null, 
    "university_id" : null, 
    "type" : "quiz", 
    "name" : "Enter scheduled quiz without end date", 
    "description" : "Even after detailed market research, some products just don't work in the market. Here's a case study from the Coca-Cola range. ", 
    "quizpoll_image" : "story_7.jpeg", 
    "status" : "1", 
    "quizpoll_type" : "scheduled", 
    "duration" : {
        "duration_type" : "Question wise", 
        "total_duration" : "1000"
    }, 
    "questions" : [
        {
            "question_id" : "5aeaa4021b7e6f00dc80c5c6"
        }, 
        {
            "question_id" : "5aeaa59d1b7e6f00dc80c5d2"
        }
    ], 
    "date_type" : {
        "start_date" : ISODate("2018-05-01T00:00:00.000+0000")
    }, 
    "created_at" : ISODate("2018-05-01T00:00:00.000+0000"), 
    "updated_at" : ISODate("2018-04-26T07:58:17.795+0000")
}

这是我正在尝试的查询:

var isoCurrentDate = current_date.toISOString();
        var quizScheduledData = await QuizListingCollection.find({
                where: ({
                    'type':'quiz',
                    'status':'1',
                    'quizpoll_type':'scheduled',
                    'date_type' :{
                            'start_date':{
                                '>': isoCurrentDate       
                            }
                        }
                    })
            });

这是我在邮递员中点击此 api 时遇到的错误

{
    "cause": {
        "name": "UsageError",
        "code": "E_INVALID_CRITERIA",
        "details": "Could not use the provided `where` clause.  Could not filter by `date_type`: Unrecognized modifier (`start_date`) within provided constraint for `date_type`."
    },
    "isOperational": true,
    "code": "E_INVALID_CRITERIA",
    "details": "Could not use the provided `where` clause.  Could not filter by `date_type`: Unrecognized modifier (`start_date`) within provided constraint for `date_type`."
}

【问题讨论】:

    标签: sails.js sails-mongo


    【解决方案1】:
    {
    where: {
            'type':'quiz',
            'status':'1',
            'quizpoll_type':'scheduled',
            'date_type.start_date': {
                    '>' : isoCurrentDate 
        }
      }
    }
    

    【讨论】:

    • . operator 我早些时候尝试过它也无法正常工作。
    • 虽然我正在尝试其他一些解决方法,但我试过它不起作用
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-18
    • 2017-05-07
    • 1970-01-01
    • 1970-01-01
    • 2012-04-28
    • 1970-01-01
    • 2016-12-31
    相关资源
    最近更新 更多