0

I need to find all objects that were created with a wrong value and what indicates that is the length of a string in it.

I've already tried to use the suggestions from this answer but Cosmos says that neither $expr and $where are supported.

Is it possible without looping through all objects?

juliano.net
  • 7,982
  • 13
  • 70
  • 164
  • 1
    I think you're asking how to query for items with a property string length comparison. If so it would be clearer to edit the question and say simply that without mentioning searching for "wrong values". – Noah Stahl Jul 28 '21 at 12:52
  • Also, clarify what you mean by "looping through" objects? Are you wanting to avoid retrieving all items into your client, or wanting a query that utilizes an index without doing a scan? – Noah Stahl Jul 28 '21 at 12:54
  • Title edited. I mean without retrieving into my client and using forEach to check each one. – juliano.net Jul 28 '21 at 12:55
  • I was more thrown off by the first sentence actually.... – Noah Stahl Jul 28 '21 at 12:56

1 Answers1

0

In the mean time, I've been able to do what I need using this:

aggregate(
    [
        { 
            "$match" : { 

            }
        }, 
        { 
            "$redact" : { 
                "$cond" : [
                    { 
                        "$lt" : [
                            { 
                                "$strLenCP" : { 
                                    "$convert" : { 
                                        "input" : "$_id", 
                                        "to" : "string", 
                                        "onError" : "Error occurred", 
                                        "onNull" : "Input null"
                                    }
                                }
                            }, 
                            36.0
                        ]
                    }, 
                    "$$KEEP", 
                    "$$PRUNE"
                ]
            }
        }, 
        { 
            "$project" : { 
                "_id" : 1.0
            }
        }
    ]
);
juliano.net
  • 7,982
  • 13
  • 70
  • 164