MongoDB中执行查询与使用Javascript希腊字符不返回任何结果 [英] Executing Queries in MongoDB with Greek Characters using Javascript Returns No Results

查看:127
本文介绍了MongoDB中执行查询与使用Javascript希腊字符不返回任何结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我建立一个HTML5应用程序结合的 AngularJS 的框架和 MongoDB的。设置类似于线建立一个后端演示了AngularJS主页。到目前为止,我已成功地保存在一个单一的只是大量的文件 - 结构化的MongoDB集合(托管Mongolab)。这些文件包括与拉丁字符和值与希腊字母或数字的人键:

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}

我是pretty确保这些文件是UTF-8 EN codeD。问题是,当我尝试查询与JS数据库,传递一个包含希腊字符的字符串,我得到结果为零。

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);

使用PHP相同的查询返回正确的结果。用数值或拉丁字符的所有其他查询成功执行(无论是从PHP或JS)。所以,唯一的问题是,当我试图通过用希腊字母JS来查询数据库。

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.

我已经检查了JS文件的编码为UTF-8,我已经设置了HTML元charset属性为UTF-8。我也曾尝试查询数据库,没有成功,虽然之前编码的查询字符串为UTF-8。

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:

> db.test.insert({ "name": "Νίκος", "value": 1.35});
> db.test.find({name: "Νίκος"});
{ "_id" : ObjectId("4f9b1642c26c79dac82740c5"), "name" : "Νίκος", "value" : 1.35 }

双重检查的JS文件编码文件?虽然,我在你真正的程序敢肯定,你有一个搜索值从URL连接通过GET或POST codeD表单来的,所以JS文件的编码不会有问题。

Double check your file encoding on the js file? Although, I'm sure in your real program, you have that search value coming from a URL encoded form through GET or POST, so the encoding on the js file wouldn't matter.

您可以尝试设置接收字符集=表单中的UTF-8。如果通过角绑定的Ajax或张贴通过JS,确保你把它和之前的字符编码​​设置。像这样的事情? http://groups.google.com/group/angular/browse_thread/thread/e6701e749d4bc8ed

You might try setting accept-charset="utf-8" in your form. If it's AJAX or posted through JS via the angular bindings, make sure that the character encoding is set before you send it as well. Something like this? http://groups.google.com/group/angular/browse_thread/thread/e6701e749d4bc8ed

这篇关于MongoDB中执行查询与使用Javascript希腊字符不返回任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆