Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

MongoDB + Nodejs insert maximum length

MongoDB + Nodejs insert maximum length


I'm trying to insert a large amount of text into a mongodb collection from nodejs. I've done some testing and found that the maximum length of the string can be only 49072. Here's how i do it:


Basically if I do a substring of (0, 49072) it works fine. (I can see the collection in mongodb). But if i do (0, 49073) then it just never appears in the db. There is no error either (I tried using {safe:true}, and using an error function to capture any errors...there weren't any).

I'm using as my mongo driver.

Anyone have any clues what could be wrong here? I think it might be some Javascript maximum string length restriction, but if it is how do i still insert large text?


Problem courtesy of: Felix Khazin


I've got a test in master that inserts a 50000 character string

passes without any problems so this might be a red herring and the problem could be somewhere else. I would suggest you try the test and see if it passes. also make sure you are on the latest node.js version and latest npm package.

Solution courtesy of: christkv


View additional discussion.

This post first appeared on Node.js Recipes, please read the originial post: here

Share the post

MongoDB + Nodejs insert maximum length


Subscribe to Node.js Recipes

Get updates delivered right to your inbox!

Thank you for your subscription