Reputation: 9411
When I am passing a long line with multiple inserts in mongo shell I get unclear errors:
2020-07-13T15:59:21.264+0100 E QUERY [js] uncaught exception: SyntaxError: expected expression, got ']' :
@(shell):1:0
I figured out it is due to the line buffer length.
How can I make it longer?
Upvotes: 3
Views: 1710
Reputation: 9411
It seems there is a hard limit to the Mongo shell line lengths:
Shell @ MongoDB Limits and Thresholds
The mongo shell prompt has a limit of 4095 codepoints for each line. If you enter a line with more than 4095 codepoints, the shell will truncate it.
Here are more details
and the exact limit origin of4095 codepoints
Apparently, without a way to configure and extend it.
Upvotes: 1
Reputation: 68
In case it's an option for you, a simple way around this limitation is to just divide your statement into multiple lines.
As an example, if your statement looks like this:
db.my_collection.aggregate([{
"$match": {
"foo": {
"$in": [1, 2, 3, 4, 5, 6, (...), 2000, 2001, 2002] // line longer than supported
}
}
}])
You can divide the long line into smaller chunks so that each line is no longer than the limit:
db.my_collection.aggregate([{
"$match": {
"foo": {
"$in": [1, 2, 3, 4, 5, 6, (...), // line shorter than limit
2000, 2001, 2002]
}
}
}])
Upvotes: 0