mongodb - mongo type matching changes when using an index -
I'm trying to write an automated test to make sure that some fields in my archive have a consistent Are the types. For each of these fields, I have a required type I therefore I am querying for those documents that ignore the field with a different type of documents, where the field is missing or zero.
When an index exists on the field, it seems that there is no difference between numerical type 1 (double), 16 (32-bit int) and 18 (64-bit int). I'm using Mongo 2.6.1. Here is a session that shows the problem:
Insert a document into a new collection, it has a field x that is 32-bit int:
& gt; Db.typetest.insert ({x: numberINT (1)} TypeRestalt ({"NINSATIED": 1}) Note that $ type only matches type 16 (32-bit int). , As expected: & gt; Db.typetest.find ({x: $ type: 1}}) & gt; Db.typetest.find ({x: {$ type: 16}}} {"_id": ObjectId ("53d52620eb3748b3f9cde293"), "x": 1} & gt; Db.typetest.find ({x: {$ Type: 17}}) & gt; Db.typetest.find ({x: {$ type: 18}})
I need to search for documents that do not match the given type, and the expected form $ Does not work from:
& gt; Db.typetest.find ({x: {$ not: {$ type: 1}}}) {"_id": ObjectId ("53d52620eb3748b3f9cde293"), "x": 1} & gt; Db.typetest.find ({x: {$ not: {$ type: 2}}}) {"_id": ObjectId ("53d52620eb3748b3f9cde293"), "x": 1} & gt; Db.typetest.find ({x: {$ no: {$ type: 16}}})) gt; Db.typetest.find ({x: {$ not: {$ type: 18}}}} {"_id": ObjectID ("53d52620eb3748b3f9cde293"), "x": 1}
After creating an index, $ type works but $ $ $ does not distinguish between type 3 numerical types:
& gt; Db.typetest.ensureIndex ({x: 1}) {"created collationautomatically": incorrect, "numIndexesBefore": 1, "numIndexesAfter": 2, "OK": 1} & gt; & Gt; Db.typetest.find ({x: $ type: 1}}) & gt; Db.typetest.find ({x: {$ type: 16}}} {"_id": ObjectId ("53d52620eb3748b3f9cde293"), "x": 1} & gt; Db.typetest.find ({x: {$ Type: 17}}) & gt; Db.typetest.find ({x: $ type: 18}}) & gt; & Gt; Db.typetest.find ({x: {$ no: {$ type: 1}}})) gt; Db.typetest.find ({x: {$ no: {$ type: 16}}})) gt; Db.typetest.find ({x: {$ no: $$ type: 18}}})) (" > If it is expected to behave for demands, then it would be good to know. If this is a bug or boundary of Mongo, then I would be interested in other ways to do this test. Where I want to save $ possibly (for demonstration reasons) because these tests will run on our production database often.
I rejected your $ type
query MongoDB 2.6.1, 2.6. 3, and at 2.4.10.
It looks like MongoDB 2.4. 10 returns the expected results, but there is a bug in 2.6 Query Planner.
There is a hint to use index that does not include field to reject field $ type
expected:
Mongo DB 2.6 .3 & gt; Db.typetest.find ({x: $$: {$ type: 18}}}. Sign ({_ id: 1}) {"_id": ObjectId ("53d600acbcad4e0896f33c90"), "x": 1} Received 1 Record (s) in MD1 Mongo DB 2.6.3 ({$ natural: 1}) {"_id": ObjectId ("53d600acbcad4e0896f33c90"), "x": 1} MongoDB 2.6.3 in 1 MMS & gt; 1 Record received
I have added your examples in a bug report that you can see / upvote.
Comments
Post a Comment