1

Is there any possibility to remove accents from specific field in project stage or any other aggregation stage?

My input document looks like this:

{
   "title" : "Está comprometido",
   "value" : "3"
}, 

And I need this output:

{
   "title" : "Esta_comprometido",
   "value" : "3"
},
Fathma Siddique
  • 266
  • 3
  • 15
Gudari
  • 287
  • 1
  • 16
  • What about the underscore character? – Wernfried Domscheit Feb 24 '20 at 11:05
  • @WernfriedDomscheit It doesn't matter, I know how to add the underscore. The problem is how to remove accents. If you can provide a solution please feel free to answer – Gudari Feb 24 '20 at 11:07
  • Do you have the possibility to do this change somewhere else in the client? String related functions are not very strong in MongoDB. – Wernfried Domscheit Feb 24 '20 at 11:10
  • I thought maybe there could be any clean and elegant solution in aggregation framework to do this. The fact is that In next step I need to use this title value as object key and "value" as object value. Like: { "Esta_comprometido": 3} – Gudari Feb 24 '20 at 11:14
  • Well, **finding** such documents is rather simple with `$regex` or `$regexFindAll`. However, in order to modify them you have to write a lot of ugly code with `$substrCP`, `$concat`, `$indexOfCP`, etc. Maybe better use JavaScript or something else for that. – Wernfried Domscheit Feb 24 '20 at 12:22
  • I hope in next mongodb version will add string features. Thanks in advance @WernfriedDomscheit – Gudari Feb 24 '20 at 12:29

1 Answers1

0

According to @WernfriedDomscheit suggestion. I finally solved the issue using client postprocessing. I'm using javascript as client

Here I post a jsbin example of how I solved this:

https://jsbin.com/kecikomuja/edit?html,js,output

I'm ussing normalize("NFD").replace(/[\u0300-\u036f]/g, "") to replace accents

This stackoverflow post gave me the idea https://stackoverflow.com/a/37511463/6329540

Gudari
  • 287
  • 1
  • 16