动态构建查询时嵌入文档查询的问题

时间:2018-10-24 10:47:24

标签: mongoid

我正在尝试动态构建一种查询,在该查询中可以查询嵌入式文档,但失败。

但是,如果有的话,请复制查询的内容并尝试使用。

0> query
=> {:"properties.account_id"=>"5bd046d21d41c82e7c000004"}

0> Collection.where(query).to_a
=> []

0> Collection.where({:"properties.account_id"=>"5bd046d21d41c82e7c000004"}).to_a
=> [#<Collection _id: 5bd046d21d41c82e7c000006, created_at: 2018-10-24 10:17:54 UTC, updated_at: 2018-10-24 10:17:54 UTC, properties: {"account_id"=>"5bd046d21d41c82e7c000004"}>]

0> Collection.where(:"properties.account_id"=>"5bd046d21d41c82e7c000004").to_a
=> [#<Collection _id: 5bd046d21d41c82e7c000006, created_at: 2018-10-24 10:17:54 UTC, updated_at: 2018-10-24 10:17:54 UTC, properties: {"account_id"=>"5bd046d21d41c82e7c000004"}>]

而且我尝试了没有冒号

0> query
=> {"properties.account_id"=>"5bd049651d41c872d2000004"}

0> Collection.where(query).to_a
=> []

0> Collection.where({"properties.account_id"=>"5bd049651d41c872d2000004"}).to_a
=> [#<Collection _id: 5bd049651d41c872d2000006, created_at: 2018-10-24 10:28:53 UTC, updated_at: 2018-10-24 10:28:53 UTC, properties: {"account_id"=>"5bd049651d41c872d2000004"}>]

解释数据也很好

{
  "queryPlanner" => {
    "plannerVersion" => 1, "namespace" => "db_testing.coll_test", "indexFilterSet" => false, "parsedQuery" => {
      "properties.account_id" => {
        "$eq" => "5bd04bf91d41c8d153000004"
      }
    }, "winningPlan" => {
      "stage" => "COLLSCAN", "filter" => {
        "properties.account_id" => {
          "$eq" => "5bd04bf91d41c8d153000004"
        }
      }, "direction" => "forward"
    }, "rejectedPlans" => []
  }, "executionStats" => {
    "executionSuccess" => true, "nReturned" => 0, "executionTimeMillis" => 1, "totalKeysExamined" => 0, "totalDocsExamined" => 2, "executionStages" => {
      "stage" => "COLLSCAN", "filter" => {
        "properties.account_id" => {
          "$eq" => "5bd04bf91d41c8d153000004"
        }
      }, "nReturned" => 0, "executionTimeMillisEstimate" => 0, "works" => 4, "advanced" => 0, "needTime" => 3, "needFetch" => 0, "saveState" => 0, "restoreState" => 0, "isEOF" => 1, "invalidates" => 0, "direction" => "forward", "docsExamined" => 2
    }, "allPlansExecution" => []
  }, "serverInfo" => {
    "host" => "ubuntu", "port" => 27017, "version" => "3.0.15", "gitVersion" => "b8ff507269c382bc100fc52f75f48d54cd42ec3b"
  }
}

有什么想法吗?

0 个答案:

没有答案