Executing Queries in MongoDB with Greek Characters using Javascript Returns No Results


I am building an HTML5 app combining the AngularJS framework and MongoDB. The setup is similar to the ‘Wire up a backend’ demo in the AngularJS home page. So far, I have managed to save a large amount of documents in a single simply - structured MongoDB collection (hosted on Mongolab). These documents contain keys with latin characters and values with greek characters or numeric ones:

{ "name": "Νίκος", "value": 1.35}

I am pretty sure these documents are utf-8 encoded. The problem is that when I try to query the database with JS, passing strings containing greek characters, I get zero results.

var queryString = "{\"name\": \"Νίκος\"}";
$scope.query_results = Project.query({q: query_string}, null, $scope.query_success);

The same queries using php return the correct results. All other queries with numeric values or Latin characters are successfully executed (either from php or js). So the only problem is when I try to query the db through js using greek characters.

I have checked the encoding of the js documents to be utf-8 and I have set the html meta charset attribute to utf-8. I have also tried encoding the query string to utf-8 before querying the database, with no success though.

Any ideas? Thanks.


Works for me from the shell (I copied your example document to insert, and then copied from the query for name), so at least you're not having one of those issues where the utf-8 characters look the same but are slightly different:

This video can help you solving your question :)
By: admin