[SERVER-29269] Issue with the "$gt and $lt" options in Aggregation Pipeline Created: 18/May/17  Updated: 19/May/17  Resolved: 19/May/17

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 3.2.11
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Marwa FRIAA [X] Assignee: Unassigned
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Capture.PNG    
Operating System: ALL
Participants:

 Description   

My collection containes documents as follow:
*****************************************************************
/* 1 */

{ "_id" : ObjectId("591dae6ae320467808f1e198"), "scenario" : "delc", "datavalue" : [ " _value: ", "A _value: 8", "B _value: 5", "C _value: 2", "D _value:4" ] }

/* 2 */

{ "_id" : ObjectId("591dae83e320467808f1e199"), "scenario" : "delc", "datavalue" : [ " _value: ", "A _value: 4", "B _value: 5", "C _value: 92", "D _value:94" ] }

/* 3 */

{ "_id" : ObjectId("591dae9ae320467808f1e19a"), "scenario" : "delc", "datavalue" : [ " _value: ", "A _value: 2", "C _value: 2", "D _value:4" ] }

**********************************************************************

When I want to search for "datavalue grater than A _value: 6" it does not work (returns all the documents) with simple $match $project as follow :
*************************************************
db.getCollection('test').aggregate([
{$match : {datavalue :

{ $gt : 'A _value: 6'}

}},
{ $project: { scenario: 1,
datavalue: { $filter: { input: "$datavalue", as: "datavalue",
cond: {
$or: [ { $eq: [

{ $substr: [ "$$datavalue", 0, 1 ] }

, "A" ] } ] } } }
} }])
*************************************************
If I add another $match (the same as the first one) to the pipeline the results are OK, but if I add a condition "searching for documents with datavalue grater than A _value: 6 and datavalue starts with B" it returns all the documents (I attached an image)



 Comments   
Comment by Kelsey Schubert [ 19/May/17 ]

Hi Marwa FRIAA,

This is the expected behavior since the query is looking for an array that has values greater than "A_value: 6" (which is a string). Please note that the string "B_value" is greater than the string "A_value...".

As I mentioned earlier, for MongoDB-related support discussion please post on the mongodb-user group or Stack Overflow with the mongodb tag. A question like this involving more discussion would be best posted on the mongodb-users group.

See also our Technical Support page for additional support resources.

Regards,
Thomas

Comment by Marwa FRIAA [X] [ 18/May/17 ]

But it works with $lt in other examples it works with $gt and not $lt . I don't understand why ..

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