2017-01-24 13 views
0

をモンゴするために、私は、クエリをモンゴするには、以下のSQLを変換したい:変換のSQLクエリは、クエリ

SELECT brand_name, 
    count(`inventory`) AS totalstock, 
    count(if(`inventory`=0, `inventory`, NULL)) as outofstock, 
    count(if(`inventory`!=0, `inventory`, NULL)) as availablestock, 
    DATE_ADD(stock_updated_at, INTERVAL 318 minute) as stock_updated_at 
FROM x group by Brand order by stock_updated_at desc; 

が、私はグループでそれを使用しなくても、プロジェクト内のstock_updated_atを見つけたいです。

これは、既存のコンバータを使用して試すことができます私のmongoquery

db.x.aggregate([  
    { 
     "$group": {  
      "_id": { "Brand": "$Brand"},   
      "TotalStock": { "$sum": 1 },  
      "OutOfStock": { "$sum": .... 
     .... 
    .... 

答えて

0

たぶん、あなたはhttps://github.com/alonho/pql

PQLは、Python-クエリ言語の略で試すことができます。 PQLは、Pythonの式をMongoDBのクエリに変換します。

>>> import pql 
>>> pql.find("a > 1 and b == 'foo' or not c.d == False") 
{'$or': [{'$and': [{'a': {'$gt': 1}}, {'b': 'foo'}]}, {'$not': {'c.d': False}}]} 
関連する問題