MongoDB에서 $ in 쿼리에 전달되는 최대 매개 변수 수는 얼마입니까?
MongoDB에서 $ in 쿼리에 전달되는 최대 매개 변수 수는 얼마입니까?
쿼리 자체는 문서입니다 . MongoDB는 문서 크기 (버전 2.4.0 이상 기준)를 16MB로 제한합니다.
정말로, 당신이 찾기로하고있는 것은 :
db.collectionName.find(queryDoc)
여기서 'queryDoc'는 다음과 같습니다.
{ 'fieldOne' : { $in : [ 1, 2, 3, 4] } }
$ in 쿼리에 전달할 수있는 최대 값 수를 찾으려면 bsonsize 명령을 사용합니다 .
mongos> Object.bsonsize([1])
16
mongos> Object.bsonsize({ 'fieldOne' : { $in : [ 1, 2, 3, 4] } })
74
mongos> Object.bsonsize({ 'fieldOne' : { $in : [ 1, 2, 3, 4, 5] } })
85
mongos> Object.bsonsize({ 'fieldOne' : { $in : [ 1, 2, 3, 4, 5, 6] } })
96
따라서 모든 추가 정수의 크기는 11 바이트임을 알 수 있습니다. 11 비트가 아니라 11 바이트입니다. 이는 BSON이 내부적으로 각각 64 비트 이상의 숫자와 래퍼를 저장하는 방식 때문입니다. 이것은 다음과 같이 쉽게 볼 수 있습니다.
mongos> Object.bsonsize({ 'fieldOne' : { $in : [ 1, 2, 3, 4, 5, 6, 69000] } })
107
mongos> Object.bsonsize({ 'fieldOne' : { $in : [ 1, 2, 3, 4, 5, 6, 6900000] } })
107
mongos> Object.bsonsize({ 'fieldOne' : { $in : [ 1, 2, 3, 4, 5, 6, 69000000000] } })
107
mongos> Object.bsonsize({ 'fieldOne' : { $in : [ 1, 2, 3, 4, 5, 6, 69000000000000] } })
107
mongos> Object.bsonsize({ 'fieldOne' : { $in : [ 1, 2, 3, 4, 5, 6, 6900000000000000] } })
107
mongos> Object.bsonsize({ 'fieldOne' : { $in : [ 1, 2, 3, 4, 5, 6, 690000000000000000] } })
107
mongos> Object.bsonsize({ 'fieldOne' : { $in : [ 1, 2, 3, 4, 5, 6, 69000000000000000000] } })
107
mongos> Object.bsonsize({ 'fieldOne' : { $in : [ 1, 2, 3, 4, 5, 6, 6900000000000000000000] } })
107
mongos> Object.bsonsize({ 'fieldOne' : { $in : [ 1, 2, 3, 4, 5, 6, 69000000000000000000000000] } })
107
따라서 개별 숫자의 크기에 관계없이 동일한 bsonsize입니다.
질문 자체 : 쿼리 문서의 크기는 얼마입니까?
pymongo에서 mongos javascript 프롬프트를 통해 $ in 절이있는 단일 필드 쿼리에 대해 추가하면 $ in 쿼리의 최대 크기에 대해 동일한 추가 사실이 표시됩니다.
mongos> Object.bsonsize({ 'a' : { '$in' : [1] }})
34
mongos> Object.bsonsize({ '' : { '$in' : [1] }})
33
mongos> Object.bsonsize({ '' : { '$in' : [] }})
22
- 쿼리 문서 자체는 22 바이트입니다.
- 필드 이름의 각 바이트는 단일 바이트를 추가합니다.
- $ in 절에 추가 된 각 숫자는 11 바이트를 추가합니다.
따라서 1 바이트 필드 이름 (실제로 최소값)이 있다고 가정하면 최대 값은 다음과 같습니다.
mongos> 16*1024*1024
16777216
mongos> (16*1024*1024) - 22 - 1
16777193
mongos> ((16*1024*1024) - 22 -1) / 11
1525199.3636363635
답변 : 1,525,198 (150 만 개입니다. 꽤 큽니다.)
제한이없는 것 같습니다.
나는 작은 테스트를했다.
1) 컬렉션 A에는 100 만 개의 간단한 JSON 개체 {id :, name :}
2) 컬렉션 B에서 다음 예외가 발생할 때까지 컬렉션 A의 참조 ID를로드했습니다. 최대 450k의 참조 횟수를 삽입 할 수 있습니다.
Exception in thread "main" com.mongodb.MongoInternalException: DBObject of size 18388885 is over Max BSON size 16777216
3) I could send 450k of these ids as $in[id1...id450000] and pull the whole list of 450k ids from 1 Million objects in collection A.
Wow! this is more more more than enough for my application :D. MongoDB is really cool.
I think the limitation is just determined by the size of a BSONDocument. When you define a query, you can keep adding values into an $in clause up until you exceed the maximum document size. So how many values you can have in the clause depends on how big each value is (the smaller the size of each value, the more you can include in the $in clause).
In terms of performance, from what I've found, there is a "sweet spot" for the number of values in an $in clause. See my answer in this related question: Is it OK to query a MongoDB multiple times per request?
i.e. balancing number of values in $in clause vs number of queries sent. I'm mid way through a blog post on that to try and dive into more detail.
'program story' 카테고리의 다른 글
SessionTimeout : web.xml 대 session.maxInactiveInterval () (0) | 2020.12.11 |
---|---|
PHP cURL HTTP PUT (0) | 2020.12.11 |
"현재 사용 중이므로 데이터베이스를 삭제할 수 없습니다." (0) | 2020.12.11 |
연결된 응용 프로그램으로 파일 열기 (0) | 2020.12.11 |
플롯 할 matplotlib Axes 인스턴스를 얻는 방법은 무엇입니까? (0) | 2020.12.11 |