[SERVER-30075] Document within the domain of an index is not returned by query Created: 10/Jul/17  Updated: 03/Aug/17  Resolved: 11/Jul/17

Status: Closed
Project: Core Server
Component/s: Index Maintenance
Affects Version/s: None
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Elyes Gherib Assignee: Kelsey Schubert
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

MongoDB Atlas 3-nodes replica set
MongoDB v3.2.13


Operating System: ALL
Participants:

 Description   

I have a document that should be returned by a query but isn't.

Query:

db.collection1.find({
    location: {
        $near: {
            $geometry: {
                'type': 'Point',
                'coordinates': [ 2.350051, 48.8606455 ]
            },
            $maxDistance: 100000
        }
    },
    $or: [
        { booleanField3: false },
        { booleanField3: { $exists: false } }
    ],
    stringField1: { $in: [ "bar" ] },
    dateField1: ISODate("2017-07-05T00:00:00.000Z")
})

Index (not sparse, not background):

{
    "stringField1" : 1,
    "booleanField1" : 1,
    "booleanField2" : 1,
    "booleanField3" : 1,
    "booleanField4" : 1,
    "booleanField5" : 1,
    "booleanField6" : 1,
    "intField1" : -1,
    "stringField2" : 1,
    "dateField1" : 1,
    "dateField2" : 1,
    "intField2" : 1,
    "intField3" : 1,
    "intField4" : 1,
    "location" : "2dsphere"
}

Document:

{
    _id: ObjectId("SOME_ID"),
    "location" : {
        "latitude" : 48.8620365,
        "longitude" : 2.3202073
    },
    booleanField1: true,
    booleanField2: true,
    booleanField3: false,
    booleanField5: true,
    stringField1: "bar",
    dateField1: ISODate("2017-07-05T00:00:00.000Z")
    /*
        Other fields
    */
}

When I insert a document with a new ID and the same exact field values, it doesn't get returned either.

When I insert a document with the same field values but a different value for the date field, the document is returned.

I am available for a live demo.



 Comments   
Comment by Kelsey Schubert [ 11/Jul/17 ]

Hi technical@tootsweet-app.com,

The document in question specifies latitude before longitude within the embedded document. Therefore, the document is not being returned by the query. For additional information regarding this restriction, please review our documentation on legacy coordinate pairs.

Correcting the order should resolve the issue. For example,

{
    _id: ObjectId("SOME_ID"),
    "location" : {
        "longitude" : 2.3202073,
        "latitude" : 48.8620365
    },
    booleanField1: true,
    booleanField2: true,
    booleanField3: false,
    booleanField5: true,
    stringField1: "bar",
    dateField1: ISODate("2017-07-05T00:00:00.000Z")
    /*
        Other fields
    */
}

Please note that SERVER project is for reporting bugs or feature suggestions for the MongoDB server. For MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag. A question like this would be best posted on the mongodb-users group.

Kind regards,
Thomas

Comment by Elyes Gherib [ 10/Jul/17 ]

Sorry for the horrible formatting, here it is:

Query:

db.collection1.find({
    location: {
        $near: {
            $geometry: {
                'type': 'Point',
                'coordinates': [ 2.350051, 48.8606455 ]
            },
            $maxDistance: 100000
        }
    },
    $or: [
        { booleanField3: false },
        { booleanField3: { $exists: false } }
    ],
    stringField1: { $in: [ "bar" ] },
    dateField1: ISODate("2017-07-05T00:00:00.000Z")
})

Index (not sparse, not background):

{
    "stringField1" : 1,
    "booleanField1" : 1,
    "booleanField2" : 1,
    "booleanField3" : 1,
    "booleanField4" : 1,
    "booleanField5" : 1,
    "booleanField6" : 1,
    "intField1" : -1,
    "stringField2" : 1,
    "dateField1" : 1,
    "dateField2" : 1,
    "intField2" : 1,
    "intField3" : 1,
    "intField4" : 1,
    "location" : "2dsphere"
}

Document:

{
    _id: ObjectId("SOME_ID"),
    "location" : {
        "latitude" : 48.8620365,
        "longitude" : 2.3202073
    },
    booleanField1: true,
    booleanField2: true,
    booleanField3: false,
    booleanField5: true,
    stringField1: "bar",
    dateField1: ISODate("2017-07-05T00:00:00.000Z")
    /*
        Other fields
    */
}

Generated at Thu Feb 08 04:22:36 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.