I have a collection with about 200K documents like this:
db.place.find()[0]
{
\"_id\" : ObjectId(\"5290de1111afb260363aa4a1\"),
\"name\" : \"place X\
Because you happen to have exact format of the field every time (circle is a two element array) you can transform it in aggregation framework into two fields and then compare them in a projection, and match to get back just the elements satisfying your requirement of second array element being greater than first array element.
db.place.aggregate( [
{ $unwind : "$center" },
{ $group : { _id : "$_id",
centerX : {$first:"$center"},
centerY : {$last:"$center"}
} },
{ $project : { YgtX : { $gt : [ "$centerY", "$centerX" ] } } },
{ $match : { YgtX : true } }
] );
Now, if your array was an arbitrary pair of numerical values, then you can use the above.
You said in comments that your pair represented coordinates (lat, long) - keep in mind that in MongoDB coordinate pairs are always stored as long, lat - if your actual x, y values were coordinates in on a flat (as opposed to spherical) place, you could find all the documents that had Y coordinate greater than X coordinate with a single geospatial query:
db.place.find( { center : { $geoWithin : { $geometry : {
type:"Polygon",
coordinates:[[[50,50],[-50,50],[-50,-50],[50,50]]]
} } } } );
The above query assumes that your coordinate system goes from -50 to 50 along X and Y and it finds all points in the triangle that represents all coordinates having Y >= X.
You can not do the query you want in a simple way in mongo because mongo does not support searching or updating based on the element in the collection. So even such simple document as {a : 1, b : 1}
and find the document where a = b is impossible without $where
clause.
The solution suggested by idbentley db.place.find({'center.0':{'$gt':'center.1'}})
will not work as well (also will not generate an error) because this way you will compare center.0 to a string 'center.1'. Therefore correct solution is the solution of Victoria Malaya (but she forgot to put .count() in the end).
One thing I would like to suggest. Anything with where is very very slow. So if you plant to do this query more then once, think about creating additional field which will store this precomputed result (you can do it in a similar fashion with this answer).
It seems that you need to use $where operator instead.
db.place.find({$where: function() {return this.center[0] > this.center[1]}})
For example, there are 3 documents in collection:
{ "_id" : ObjectId("52910457c7d99f10949e5a85"), "name" : "place X", "center" : [ 2, 3 ] }
{ "_id" : ObjectId("52910463c7d99f10949e5a86"), "name" : "place Y", "center" : [ 3, 2 ] }
{ "_id" : ObjectId("5291046ac7d99f10949e5a87"), "name" : "place Y", "center" : [ 8, 9 ] }
The result of the $where command will be:
{ "_id" : ObjectId("52910463c7d99f10949e5a86"), "name" : "place Y", "center" : [ 3, 2 ] }