代码之家  ›  专栏  ›  技术社区  ›  Mansa

MongoDB在调用字符串内比较int

  •  1
  • Mansa  · 技术社区  · 6 年前

    "data": {
        "type": "MatchData",
        "matchId": "5b34f2d527f0d904f8ee4bbf",
        "groupId": "5b2a032ffc37de04f30dc412",
        "leaderboardId": "5b2a0387fc37de04f30e149d",
        "matchTitle": "",
        "date": "20180628144304"
    }
    

    var currDate = 20180928000000
    dbCollection('matches').find( { "groupId": groupId, "$lt": {"date": currDate} } );
    

    希望得到帮助和提前感谢:-)

    1 回复  |  直到 6 年前
        1
  •  1
  •   Ashh    6 年前

    您可以转换输入参数 currDate 到字符串

    var currDate = "20180928000000"
    dbCollection('matches').find({ "groupId": groupId, "$lt": { "date": currDate } })
    

    4

    那你可以用 $toInt 聚合运算符

    dbCollection('matches').find({
      "groupId": groupId,
      "$expr": { "$lt": [{ "$toInt": "$date" }, currDate]}
    })