Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a length limit to field values in mongo queries?

Tags:

mongodb

I've got a single document in a collection:

{
  _id: ObjectId("508836afea5cea2ccec11a0d"),
  created_at: 1348657869.204,
  name: "Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx Abcdefghijklmnopqrstuvwx"
}

I can find it with

find({"created_at":1348657869.204})

but

find({"name":"Abcd...<actual name here>...uvwx"})

returns no results. Is there a length limit to the field in the query?

like image 296
Parker Avatar asked Nov 02 '12 02:11

Parker


People also ask

What is the limit of in query MongoDB?

In MongoDB, the limit() method limits the number of records or documents that you want. It basically defines the max limit of records/documents that you want. Or in other words, this method uses on cursor to specify the maximum number of documents/ records the cursor will return.

Can MongoDB handle millions of records?

Working with MongoDB and ElasticSearch is an accurate decision to process millions of records in real-time. These structures and concepts could be applied to larger datasets and will work extremely well too.

How do I get the length of a field in MongoDB?

As for the logical condition, there are String Aggregation Operators that you can use $strLenCP operator to check the length of the string. If the length is $gt a specified value, then this is a true match and the document is "kept". Otherwise it is "pruned" and discarded.

How do you value a field in MongoDB?

You can extract the value of a field by appending that field's name to your query when using findOne() .


1 Answers

The limit you are encountering is the maximum line buffer size in the mongo shell, which is 4096 bytes as at MongoDB 2.2.1. If you try pasting your example in the mongo shell you should notice that you cannot add any characters beyond the line limit.

If you execute this query from a language driver you will not have this issue.

You could also workaround this in the mongo shell by loading the query from a JavaScript file specified on the command line:

 mongo longname.js

Or by creating a long string in the mongo shell programmatically:

// Longname will be 5000 characters
var longname = '';
for (i = 0; i < 200; i++) {
    longname += 'Abcdefghijklmnopqrstuvwx ';
}

db.foo.insert({
  _id: ObjectId("508836afea5cea2ccec11a0d"),
  created_at: 1348657869.204,
  name: longname
});

printjson(db.foo.findOne({name: longname}))
like image 50
Stennie Avatar answered Nov 09 '22 03:11

Stennie