As of April 12th, you must go to Progress SupportLink to create new support cases or to access existing cases. Please, bookmark the SupportLink URL and use the new portal to contact the support team.
let containsPredicate = NSPredicate(format: "self.name CONTAINS[c] %@", searchString)
Using the above, I get an error with the description: Regular expression in queries must be anchored at the beginning (they must start with ^)
Any idea why I'm running into this problem?
Best Answer
P
Pranav J
said
almost 4 years ago
Hi Shea and Wood,
I have investigated this thoroughly and I wanted to bring some important information to your attention. We have placed restrictions on regex queries because they are very computationally expensive given our current platform setup. We ONLY support regex for querying only to the beginning of a string and it should be case sensitive. We do not recommend the full-text regular expression searches as they are very computationally expensive. Please check this documentation link for more information.
Now coming to your NSPredicate question, "Contains" will not work because it does not begin with "^". You will have to use "beginswith" as below (it will fetch all records for which "title" column value starts with "FRI"):
let dataStore = try DataStore<Book>.collection(type: .auto)
let predicate = NSPredicate(format: "title beginswith %@", "FRI")
let sortDescriptor = NSSortDescriptor(key: "startDate", ascending: true)
let query = Query(predicate: predicate, sortDescriptors: [sortDescriptor])
dataStore.find(query) { (result: Result<AnyRandomAccessCollection<Book>, Swift.Error>) in
switch result {
case .success(let books):
//print("Entered block \(num)");
//num+=1;
print("\nBooks: \(books)")
print("\nBook count: \(books.count)")
for record in books {
print(record)
}
case .failure(let error):
print("Error: \(error)")
}
}
The generated Mongo query will be like this: /appdata/kid_xyz/Book?query={"title":{"$regex":"^FRI"}}. You can test this on the Kinvey API console.
Yes, I do. However, no one has gave any answer so I'm not too sure how I can help you since we both have the same problem.
P
Pranav J
said
almost 4 years ago
Hi Shea and Wood,
Sincere apologies as we couldn't answer your question in time. I have started working on this one and will get back to you soon.
Thanks,
Pranav
Kinvey
1 person likes this
P
Pranav J
said
almost 4 years ago
Answer
Hi Shea and Wood,
I have investigated this thoroughly and I wanted to bring some important information to your attention. We have placed restrictions on regex queries because they are very computationally expensive given our current platform setup. We ONLY support regex for querying only to the beginning of a string and it should be case sensitive. We do not recommend the full-text regular expression searches as they are very computationally expensive. Please check this documentation link for more information.
Now coming to your NSPredicate question, "Contains" will not work because it does not begin with "^". You will have to use "beginswith" as below (it will fetch all records for which "title" column value starts with "FRI"):
let dataStore = try DataStore<Book>.collection(type: .auto)
let predicate = NSPredicate(format: "title beginswith %@", "FRI")
let sortDescriptor = NSSortDescriptor(key: "startDate", ascending: true)
let query = Query(predicate: predicate, sortDescriptors: [sortDescriptor])
dataStore.find(query) { (result: Result<AnyRandomAccessCollection<Book>, Swift.Error>) in
switch result {
case .success(let books):
//print("Entered block \(num)");
//num+=1;
print("\nBooks: \(books)")
print("\nBook count: \(books.count)")
for record in books {
print(record)
}
case .failure(let error):
print("Error: \(error)")
}
}
The generated Mongo query will be like this: /appdata/kid_xyz/Book?query={"title":{"$regex":"^FRI"}}. You can test this on the Kinvey API console.
Shae Hazelwood
I'm following the syntax from https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html
let containsPredicate = NSPredicate(format: "self.name CONTAINS[c] %@", searchString)
Using the above, I get an error with the description: Regular expression in queries must be anchored at the beginning (they must start with ^)
Any idea why I'm running into this problem?
Hi Shea and Wood,
I have investigated this thoroughly and I wanted to bring some important information to your attention. We have placed restrictions on regex queries because they are very computationally expensive given our current platform setup. We ONLY support regex for querying only to the beginning of a string and it should be case sensitive. We do not recommend the full-text regular expression searches as they are very computationally expensive. Please check this documentation link for more information.
Now coming to your NSPredicate question, "Contains" will not work because it does not begin with "^". You will have to use "beginswith" as below (it will fetch all records for which "title" column value starts with "FRI"):
The generated Mongo query will be like this: /appdata/kid_xyz/Book?query={"title":{"$regex":"^FRI"}}. You can test this on the Kinvey API console.
Thanks,
Pranav
Kinvey
1 person has this question
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstWood Wayfarer
Have the same issue
Wood Wayfarer
Any news ? I need this fix ASAP
Wood Wayfarer
Shae Hazelwood
Yes, I do. However, no one has gave any answer so I'm not too sure how I can help you since we both have the same problem.
Pranav J
Hi Shea and Wood,
Sincere apologies as we couldn't answer your question in time. I have started working on this one and will get back to you soon.
Thanks,
Pranav
Kinvey
1 person likes this
Pranav J
Hi Shea and Wood,
I have investigated this thoroughly and I wanted to bring some important information to your attention. We have placed restrictions on regex queries because they are very computationally expensive given our current platform setup. We ONLY support regex for querying only to the beginning of a string and it should be case sensitive. We do not recommend the full-text regular expression searches as they are very computationally expensive. Please check this documentation link for more information.
Now coming to your NSPredicate question, "Contains" will not work because it does not begin with "^". You will have to use "beginswith" as below (it will fetch all records for which "title" column value starts with "FRI"):
The generated Mongo query will be like this: /appdata/kid_xyz/Book?query={"title":{"$regex":"^FRI"}}. You can test this on the Kinvey API console.
Thanks,
Pranav
Kinvey
1 person likes this
-
Why do I get "Undefined symbols" errors when building with KinveyKit?
-
How do I register push tokens?
-
When using social login, to perform a log-out, do I need to log out of the social network, Kinvey, o
-
How can I assign additional properties to users?
-
Does KinveyKit support 64-bit ARM devices, such as iPhone 5s?
-
Authorization Token Invalid or Expired
-
BOOL and how it is stored in the database.
-
Offline saving throwing errors
-
Custom endpoint not able to form request object
-
Security through business logic
See all 437 topics