Node.js上的MongoDB'错误:检测到非ASCII字符' [英] MongoDB 'error: non ascii character detected' on Node.js

查看:79
本文介绍了Node.js上的MongoDB'错误:检测到非ASCII字符'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将很大一部分数据解析到新的MongoDB数据库中,当我运行作业时,当我执行db.myCollection.find()时,总是会收到错误消息.
错误是error: non ascii character detected.

I'm trying to parse a very large chunk of data into a new MongoDB database and when I run the job I keep getting an error when I do db.myCollection.find().
The error is error: non ascii character detected.

我正在使用Node.js和Mongoose填充数据库.我看到的可能会引起问题的唯一字符是',-,但是我对所有字符进行了.replace处理.我尝试转义(\),并尝试将其完全删除,但似乎没有任何效果.

I am using Node.js and Mongoose to populate the database. The only characters I have seen that might be causing problems are ', , and - but I have done a .replace on all of them. I tried escaping them (\) and I tried just removing them entirely and nothing seems to be working.

我最大的问题是保存对象时没有出现任何错误,当我尝试查看集合时仅收到该消息.

My biggest problem is that I don't get any errors when I am saving the objects, I just get that message when I try to view the collection.

是否有关于清理MongoDB输入的任何信息?

Is there any information out there on sanitizing MongoDB input?

推荐答案

如果是字符串数据,则在插入之前,请确保将其编码为UTF8.大多数驱动程序都应该检查这一点,但是在Mongoose驱动程序中它可能被忽略了.根据BSON规范的定义,MongoDB中的所有字符串都存储为UTF8.

If it's string data then maybe make sure it's encoded as UTF8 before inserting. Most drivers should check this, but it could've been overlooked in the Mongoose driver. All strings in MongoDB are stored as UTF8, as defined by the BSON spec.

这篇关于Node.js上的MongoDB'错误:检测到非ASCII字符'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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