-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: Querying
-
None
-
Fully Compatible
-
ALL
I have the following collection with name travelers
{ "_id" : 1, "name" : "Dev", "nearestAirport" : "JFK", "lastUpdated" : ISODate("2020-03-20T14:34:06.749Z") } { "_id" : 2, "name" : "Eliot", "nearestAirport" : [ "JFK", "BOS" ], "lastUpdated" : ISODate("2020-03-20T14:34:06.749Z") } { "_id" : 3, "name" : "Jeff", "nearestAirport" : "BOS", "lastUpdated" : ISODate("2020-03-20T14:34:06.749Z") } { "_id" : 4, "name" : "Vijay", "nearestAirport" : "BLR", "lastUpdated" : ISODate("2020-03-20T14:34:06.749Z") } { "_id" : 5, "name" : "Reddy", "nearestAirport" : "HYD", "lastUpdated" : ISODate("2020-03-21T06:07:29.443Z") } { "_id" : 6, "name" : "Vivek", "nearestAirport" : [ "PNQ" ], "lastUpdated" : ISODate("2020-03-21T06:07:29.443Z") } { "_id" : 7, "name" : "Guru", "nearestAirport" : "BOM", "lastUpdated" : ISODate("2020-03-20T14:34:06.749Z") }The field type of 'nearestAirport' for id : 2 and 6 is Array and rest are string.
When I ran the query db.travelers.find({'nearestAirport':{'$type': 2}}) ( 2 represents type string) i get the following output
{ "_id" : 1, "name" : "Dev", "nearestAirport" : "JFK", "lastUpdated" : ISODate("2020-03-20T14:34:06.749Z") }{ "_id" : 2, "name" : "Eliot", "nearestAirport" : [ "JFK", "BOS" ], "lastUpdated" : ISODate("2020-03-20T14:34:06.749Z") }
{ "_id" : 3, "name" : "Jeff", "nearestAirport" : "BOS", "lastUpdated" : ISODate("2020-03-20T14:34:06.749Z") } { "_id" : 4, "name" : "Vijay", "nearestAirport" : "BLR", "lastUpdated" : ISODate("2020-03-20T14:34:06.749Z") } { "_id" : 5, "name" : "Reddy", "nearestAirport" : "HYD", "lastUpdated" : ISODate("2020-03-21T06:07:29.443Z") }{ "_id" : 6, "name" : "Vivek", "nearestAirport" : [ "PNQ" ], "lastUpdated" : ISODate("2020-03-21T06:07:29.443Z") }
{ "_id" : 7, "name" : "Guru", "nearestAirport" : "BOM", "lastUpdated" : ISODate("2020-03-20T14:34:06.749Z") }The output retrieves documents with field type Array also.
However when i ran the query db.travelers.find({'nearestAirport':{'$type': 4}}) , i get only two documents which are id : 2 and 6.
{ "_id" : 2, "name" : "Eliot", "nearestAirport" : [ "JFK", "BOS" ], "lastUpdated" : ISODate("2020-03-20T14:34:06.749Z") } { "_id" : 6, "name" : "Vivek", "nearestAirport" : [ "PNQ" ], "lastUpdated" : ISODate("2020-03-21T06:07:29.443Z") }Please advice why the query db.travelers.find({'nearestAirport':{'$type': 2}}) is pulling all documents with the filed type Array also when the condition is to fetch field with type string?
Let me know if i am missing something?
Below is the version of the server.