【问题标题】:How could I convert the mongoid query into real mongo query js syntax如何将 mongoid 查询转换为真正的 mongo 查询 js 语法
【发布时间】:2016-03-08 09:19:49
【问题描述】:

我在控制台上执行此查询,但是我不能简单地复制并粘贴它以在 mongo shell 中执行它。

有没有什么方法可以将mongoid DSL转换成真正的mongo查询语句。

谢谢

database=test collection=flights selector={"$query"=>{"from"=>{:$in=>["TPE"]}, "to"=>{:$in=>["HND", "NRT", "NRT|TYO"]}, "flight_date"=>{"$gte"=>2016-03-15 00:00:00 UTC, "$lt"=>2016-03-16 00:00:00 UTC}, "flight_no"=>{:$exists=>true, :$ne=>nil}, "updated_at"=>{"$gte"=>2016-03-02 09:16:13 UTC}}, "$orderby"=>{"departure_at"=>1}}

【问题讨论】:

    标签: mongoid


    【解决方案1】:

    你可以这样做:

    module Mongoid
        class Criteria
            def to_shell
                "db.#{collection.name}.find(#{selector.to_json})"
            end
        end
    end
    
    Flight.where({:from.in => ["TPE"], :to.in => ["HND", "NRT", "NRT|TYO"]}).to_shell
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-01-17
      • 2021-06-19
      • 1970-01-01
      • 2020-01-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-10-11
      相关资源
      最近更新 更多