Closed lakshmansai1980 closed 3 years ago
Please try like with regex options.
this.employeeRepository.find({
where: {
empName: {
like: "M",
options:"i"
}
}
})
Hi @rahulrkr08 I tested with the shopping app attached to a mongodb datasource, seems the like
operator works fine, could you double check with the regex? E.g. {like: 'M'}
I tested model Product
with query
{
"where": {
"name": {
// return all the names that contains letter "i"
"like": "i"
}
}
}
And it seems working fine.
The result:
``` [ { "productId": "5ea86cd959403f6e46b39dc0", "name": "iPhone 11", "price": 2200, "image": "https://images.unsplash.com/photo-1571380401583-72ca84994796?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60", "description": "The latest iPhone from Apple.", "details": "Nullam at pretium ante, id finibus est. Aenean tincidunt feugiat dui, quis commodo nisl dapibus a.\nInteger elementum consectetur felis et malesuada. Vivamus semper ipsum et ligula maximus viverra. Fusce aliquet, nunc a laoreet pellentesque, leo dui vestibulum justo, a lacinia orci magna vitae magna.\n- Nullam bibendum turpis non ex semper, quis iaculis lacus elementum. - Fusce ultricies diam a neque varius, nec pulvinar ante congue.\nDuis id posuere nisl, sit amet accumsan nunc.\n" }, { "productId": "5ea86cd959403f6e46b39dc5", "name": "DJI Mavic Pro", "price": 2300, "image": "https://images.unsplash.com/photo-1529611934128-376c7bb1c88a?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60", "description": "DJI Mavic Pro drone.", "details": "In quis nunc dolor. Proin laoreet mauris velit, nec commodo ex pharetra eget. - Curabitur dignissim dui a ex pulvinar, nec finibus eros luctus. - Lorem ipsum dolor sit amet, consectetur adipiscing elit. - Phasellus ac quam vulputate, condimentum magna pellentesque, mollis nisi.\nIn sit amet nulla enim. Aenean mi elit, mattis non rutrum vitae, consectetur sed libero.\n" }, { "productId": "5ea86cd959403f6e46b39dcb", "name": "DJI Phantom", "price": 3120, "image": "https://images.unsplash.com/photo-1521405924368-64c5b84bec60?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60", "description": "DJI Phantom drone.", "details": "Duis consectetur rutrum turpis, nec consequat nunc viverra in.\nMauris vitae maximus sem, et vehicula ex. Duis ultricies sodales semper. Nam non scelerisque ante. Aliquam in lectus enim. Donec eget purus vel lectus vestibulum blandit.\nNulla facilisi. Maecenas molestie, sem aliquet lobortis sagittis, quam eros laoreet ligula, id fermentum purus tellus a felis. Praesent convallis metus id ipsum rutrum, a consequat dui interdum. Cras porta aliquet dui ac malesuada.\n" }, { "productId": "5ea86cd959403f6e46b39dcc", "name": "MacBook Pro", "price": 2100, "image": "https://images.unsplash.com/photo-1541807084-5c52b6b3adef?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=crop&w=800&q=60", "description": "The best MacBook Pro from Apple.", "details": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent varius laoreet augue ut condimentum. Donec purus dui, aliquet eu arcu vitae, elementum viverra turpis.\n- Duis luctus justo erat, sit amet gravida felis vehicula quis. - Nunc posuere dui quis justo semper ullamcorper. - Suspendisse eu odio quis odio bibendum sodales sed quis metus. - Quisque fringilla odio ornare urna malesuada blandit.\nMaecenas hendrerit, augue ac iaculis luctus, lacus nisl tincidunt ante, eu venenatis urna lectus vitae ligula. Aenean iaculis nibh nec dolor fringilla vehicula. Nunc purus tortor, lobortis et mi eu, dapibus aliquet urna. Fusce sollicitudin dapibus dapibus. Duis nec odio id purus porttitor euismod. Aenean in ex sollicitudin, condimentum orci sed, volutpat turpis.\nVestibulum ac sapien sed massa auctor pretium. Proin scelerisque ultrices risus. Proin elementum arcu sodales, posuere tellus eu, molestie arcu. Fusce nisl risus, ornare ut quam nec, gravida interdum ante.\n" } ] ```
Hi @lakshmansai1980 any update on this 🙂 ? have you tried the regex filters above?
Hi @jannyHou , I did tried with regex and it works for me. With the like operator, I was including % , hence could not see the results .. I will try removing % and will retry once ..
@jannyHou Thanks for your reply. like
is not working when there is a space between the query value. In your example, can you able to search like {like: 'iPhone 11'}
.
Below is the (working) query URL. It returns the expected response.
/mf-schemes?filter={"where":{"name":{"like":"Mirae%20Asset%20Savings","options":"i"}}}
Below is the (not working) query URL. It returns an empty response.
/mf-schemes?filter={"where":{"name":{"like":"Mirae%20Asset%20Savings"}}}
Hi @jannyHou , Like operator is working for me. Have one more scenario which is not supporting. Here is my model
{
productName : "product1",
keyWords: ['keyword1' , 'keyword2' , 'keyword3']
}
How do I search keywords with in the array by applying like operator.. As of now, I can search for full word with in the array with 'inq'
For ex : If I want to search all products with keywords has 'key' or 'word'
@lakshmansai1980 For the option i
, according to https://docs.mongodb.com/manual/reference/operator/query/regex/#op._S_options it controls the case-sensitive, it may be not related to the space, could you check the data stored in your db and see if the case exactly match?
I tried the like
filter with space in it, and the filter works
{
"where": {
"name": {
// note there is a space here
"like": "a C"
}
},
"fields": {
"details": false,
"image": false
}
}
Have one more scenario which is not supporting
@lakshmansai1980 For the array use case, can you post the query you tried here?
This issue has been marked stale because it has not seen activity within six months. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS
file at the top-level of this repository. This issue will be closed within 30 days of being stale.
This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS
file at the top-level of this repository.
Steps to reproduce
Current Behavior
Returning empty results : []
Expected Behavior
Should return records which matches 'M'
Link to reproduction sandbox
not available
Additional information
node -e 'console.log(process.platform, process.arch, process.versions.node)' win32 x64 12.13.0
npm ls --prod --depth 0 | grep loopback
+-- @loopback/boot@2.1.0 +-- @loopback/context@3.5.0 +-- @loopback/core@2.4.0 +-- @loopback/openapi-v3@3.2.0 +-- @loopback/repository@2.2.0 +-- @loopback/rest@3.3.0 +-- @loopback/rest-crud@0.8.0 +-- @loopback/rest-explorer@2.1.0 +-- @loopback/service-proxy@2.1.0 +-- loopback-connector-mongodb@4.2.0 `-- tslib@1.11.1
Description
copied from https://github.com/strongloop/loopback-next/issues/5227#issuecomment-625780952
operator like is not working when there is a space between the query value. In your example, can you able to search like {like: 'iPhone 11'}.
Below is the (working) query URL. It returns the expected response.
/mf-schemes?filter={"where":{"name":{"like":"Mirae%20Asset%20Savings","options":"i"}}}
Below is the (not working) query URL. It returns an empty response.
/mf-schemes?filter={"where":{"name":{"like":"Mirae%20Asset%20Savings"}}}
Acceptance Criteria