Sign In Register

How can we help you today?

Start a new topic
Answered

multiple lines string in cloud code

How do we make multi lines string in cloud code ?

I'm trying to build a mongodb $where clause like this:

 

var whereQuery = "function () {
    for (var index in this.relations) {
        var current = this.relations[index];
        if (current._id == 2) { 
            return true; 
        } 
    } 
    return false;
}";

This give me a "sun.org.mozilla.javascript.internal.EvaluatorException: unterminated string literal (#192)" on the first line.

If it is not possible, is there another way to do this? Or do I really need to build the entire $where expression on one line?


Best Answer

In JavaScript you can escape the newline with a \


var whereQuery = "function () { \

    for (var index in this.relations) { \

        var current = this.relations[index]; \

        if (current._id == 2) { \

            return true; \

        } \

    } \

    return false; \

}";


Gabriel


Answer

In JavaScript you can escape the newline with a \


var whereQuery = "function () { \

    for (var index in this.relations) { \

        var current = this.relations[index]; \

        if (current._id == 2) { \

            return true; \

        } \

    } \

    return false; \

}";


Gabriel

Great! 

Thanks.

Login to post a comment