groovy
2016-04-11 10 views -1 likes 
-1

コマンドラインからrepo_date値をクエリに挿入する必要があります。以下を試してみましたが、クエリに値を挿入できません。grrovyで一重引用符で囲まれた文字列内でコマンドライン値を取得

String repo = this.args[0] 
String repo_date = this.args[1] + "T00:00:00.000Z" 

def query='items.find({"type" : "file","repo" :{"$match" : "${repo}"},"created":{"$lt": "${repo_date}").include("name","created").sort({"$asc": ["created"]})' 

エスケープ文字を使用しようとしました。

など私はあなたがクエリ内全体クエリ文字列の周りトリプル二重引用符は、二重引用符を使用している場合ではないでしょう

def query='items.find({"type" : "file","repo" :{"$match" : "xyz"},"created":{"$lt": "2010-10-10T00:00:00.000Z").include("name","created").sort({"$asc": ["created"]})' 

答えて

0

(コマンドラインから値を通過した後)クエリを必要とします構文エラーが発生する。ここに自己完結型の実例があります:

String repo = 'xyz' 
String repo_date = '2010-10-10T00:00:00.000Z' 
String match = 'something' 
String lt = 'foo' 
String asc = 'bar' 

def query = """items.find({"type" : "file","repo" :{"$match" : "${repo}"},"created":{"$lt": "${repo_date}").include("name","created").sort({"$asc": ["created"]})""" 
+0

Thanks @ Emmanuel Rosaそれは今働いている。 – user6136315

関連する問題