Probably a silly question, but if in a collection I have documents which include attributes defined with spaces, example:
{
"attribute with spaces" : "blabla",
...
}
How can I query for finding it? I tried
for document in documents
filter document."attribute with spaces" == "blabla"
But of course I get a syntax error.
Attribute names that are reserved keywords or contain spaces or other characters not allowed in attribute names must be quoted with backticks:
FOR document IN documents
FILTER document.`attribute with spaces` == "blabla"
Alternatively you can use attribute access like this:
FOR document IN documents
FILTER document["attribute with spaces"] == "blabla"
This is also explained in the documentation: https://www.arangodb.com/docs/stable/aql/fundamentals-syntax.html#names
Related
I want to search list of collections from mongoDB have all the keywords of given string.
For e.g.
I have a collection
{
"id":1
"text":"go for shopping",
"description":"you can visit this branch as well"
}
{
"id":2
"text":"check exiting discount",
"description":"We have various discount options"
}
Now, If I will pass string like "I want to go for shopping" w.r.t. text field in find query of mongoDB. Then I should get first collection as output because text field value "go for shopping" exists in the input string passed in find query.
This can be achieved through $text operator in MongoDB. But you have to createIndex on the "text" field in your database.(or whichever filed you want to be matched, I would suggest you rename it in your db to avoid confusion)
db.yourCollectionName.createIndex({"text":"text"})
The first field here is the "text" field in your database, and the second one is the mongo operator.
Then you can pass any query like,
db.yourCollectionName.find({$text: {$search: "I want to go for shopping"}})
The "$text" here is the mongo operator.
This would return all documents which have any of the keywords above.
Maybe you can read more around this and improvise and modify.
Ref: MongoDb $text
You can do so through regular expression. MongoDb provides the provision of matching strings through regex patterns.
In your case you could do something like:
db.yourCollectionName.find({text:{$regex:"go for shopping" }})
This will return you all the documents having the phrase "go for shopping" in the text field.
Ref: MongoDb Regex
I need to search mongodb collection for a specific pattern field. I tried using {$exists:true}; However, this gives results only if you provide exact field.
I tried using {$exists:true} for my field. But this does not give results if you give some pattern.
{
"field1":"value1",
"field2":"value2",
"field3":object
{/arjun1/pat1: 1,
/arjun2/pat2: 3,
/arjun3/pat3: 5
}
"field4":"value4",
}
From some field, I get the keys pat3 & field3. From this I would need to find out if the value /arjun3/pat3 exists in the document.
If I use {"field3./arjun3/pat3":{$exists:true}}, this would give me results. But the problem is I get only field3 and pat3 and I need to use some pattern matching like field3.*.pat3 and then use $expr or $exists; which I'm not exactly sure how to. Please help.
you could try something of this kind
db.arjun.find(
{"field3" : {
"$elemMatch" : { $and: [
{"arjun3.pat3" : {$exists:true}},
{"arjun3.pat3" : 5}
]
}}}
);
You can either go for regex (re module) for SQL like pattern matching, and compile your own custom wildcard. But if you don't want that then you can simple use the fnmatch module, it is a builtin library of python which allows wildcard matching for multiple characters (via*) or a single character (via ?).
import fnmatch
a = "hello"
print(fnmatch.fnmatch(a, "h*"))
OUTPUT:-
True
SuiteScript v1.
Searching on the item record type.
customrecord_sp_ecom_item_infoseo is a custom record type with a field called custrecord_sp_ecom_item_seo that references an item record. It also has a field called custrecord_sp_ecom_description, which is of type text.
I want to search for the items where the word "frozen" appears in custrecord_sp_ecom_description in the linked customrecord_sp_ecom_item_infoseo record and I want to use filter expressions.
Here's my expression:
[
[
"customrecord_sp_ecom_item_infoseo.custrecord_sp_ecom_description",
"contains",
"frozen"
]
]
And here's the error I get:
{"error" : {"code" : "SSS_INVALID_SRCH_FILTER_JOIN", "message" : "An nlobjSearchFilter contains an invalid join ID, or is not in proper syntax: custrecord_sp_ecom_description."}}
If I change the expression to:
[
[
"isonline",
"is",
true
]
]
then it works fine, albeit with the wrong results. So I know filter expressions can work, there's just something wrong with my expression.
How can I make it work?
When using the dot syntax for joins in filter expressions, the prefix of the dot is the ID of the field you are joining through, not the ID of the record type you are joining to (as it looks like you have here).
So, if I am searching Invoices, but I want to filter on the Sales Rep from the related Sales Order, it would look something like:
[
[ 'createdfrom.salesrep', 'anyof', salesReps]
]
Notice that it's not salesorder.salesrep, but rather createdfrom.salesrep because the createdfrom field is what links the record I am searching (Invoices) to the record I am joining (Sales Order). The same applies when using custom records. Your join will be something like custrecord_fieldid.custrecord_sp_ecom_description rather than using the record type.
I cannot find where to quote a field name that has a space in it, for example when doing
FILTER s._key = a.`Supplier Id`
The above, sql-style quote doesn't work, neither does array access. What's the correct way?
Figured it out now, I got bitten by SQL and forgot that equality comparison is made with == in AQL. Then the array access worked, so the way to use field names with spaces is this:
FILTER s._key == a['Supplier Id']
If the field is without spaces but has some special characters, it works to use backtick instead of array access:
FILTER s._key == a.`ÅterförsäljareId`
Edit: Another option is to use bind variables:
FILTER s._key == a.#field
// Passing this to the API as bind variables:
{
"field": "Supplier Id"
}
I have a document item called Pathname which is Text List containing paths to databases. I need to create a view, with only specific documents, which contain a specific database path in Pathname item.
I have tried these statements but none has worked:
1.#isMember("Databasepath",Pathname)
2.#Contains(#Implode(Pathname);"Databasepath")
Thank You for any suggestion.
There is no need for the "implode" in your code.
If Pathname looks like this:
apps\database1.nsf; apps\database2.nsf; mail\mailfile1.nsf;
and you want to filter out all in "apps" path, then the formula would look like this:
#Contains( PathName; "apps\\" )
Don't forget to duplicate the backslashes, if you "hardcode" them, as they are escape characters.
But now think about a Pathname containing:
localapps\db1.nsf; apps\db2.nsf; local\apps\db3.nsf
Then the formula above would select ALL entries. In that case this formula would be better:
#Contains( "#" + PathName; "#apps\\" )
Or (if the given path is always at the beginning):
#Begins( PathName; "apps\\" )
If it's truly a text list (i.e., "Path1\Db1.nsf" : "Path2\Db2.nsf" : "Path3\Db3.nsf"), then you should just be able to use the equals operator because a comparison of a scalar to a list value returns true if the scalar matches any of the list values. This detail of the semantics of formula language actually makes a lot of uses of #Contains unnecessary!
I.e., it should be as simple as
SELECT Pathname = "Path1\\Db1.nsf";
or if Pathname is not already case normalized, then
SELECT #uppercase(Pathname) = "PATH1\\DB1.NSF";