1

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.

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.

Is there any information out there on sanitizing MongoDB input?

1
  • Discovered the issue. One of the strings had this character in it: Æ (as in the word "Aether") so I just replaced it with "AE" and all is running smoothly now. Commented Jul 16, 2011 at 20:43

3 Answers 3

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Appreciate the advice, but I have no idea how to do that. :) Other strings I've saved to MongoDBs with Mongoose have worked fine so I don't think this is the problem but I'll look into it.
1

Just had the same issue. MongoDB version: 1.8.2 + Mongoose 3.3.1 (NodeJS v0.8.14) on Ubuntu (EC2)

> db.tweets.find();

error:non ascii character detected

Consensus is that upgrading to the latest version of MongoDB (2.2) will solve the issue.

Checked which version of MongoDB I was running by issuing the command:

$ mongod --version

db version v1.8.2, pdfile version 4.5 - Wed Oct 24 15:43:13 git version: nogitversion

Confirm if mongo is currently running:

$ ps -deaf | grep mongod

mongodb 15408 1 0 Jun06 ? 13:50:00 /usr/bin/mongod --config /etc/mongodb.conf

To Shutdown MongoDB

$ ./mongo

> use admin

> db.shutdownServer()

server should be down...

Then upgraded following these instructions: How to Install MongoDB on Ubuntu

Add the 10 Gen (creators of MongoDB) public key to apt-get so you trust their package:

$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10

$ echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" >> /etc/apt/sources.list.d/10gen.list

Update your packages:

$ sudo apt-get update

install 10gen's MongoDB Debian/Ubuntu package:

$ sudo apt-get install mongodb-10gen

The following packages will be REMOVED: mongodb

The following NEW packages will be installed: mongodb-10gen

If you get an error, try:

$ apt-get autoremove

Confirm that the mongodb user/group has permission to write to the data directory:

$ sudo chown -R mongodb:mongodb /var/lib/mongodb/.

Restart MongoDB with the command:

$ mongod --fork --dbpath /var/lib/mongodb/ --smallfiles --logpath /var/log/mongodb.log --logappend

Once you have the new version of MongoDB the "non ascii" character issue should be gone. :-)

Comments

0

i got it when i accidentally did this

BasicDBObject bdb; bdb.put("myfield", new ObjectId(String.valueOf(objectId)));

then saved bdb to mongo.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.