Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error in $gte aggregation expression: "Expression $gte takes exactly 2 arguments. 1 were passed in."

Tags:

mongodb

I'm getting this error while trying

db.any.aggregate([
 {  "$project": { n: {$gte: 0}}    }
])

I'm sure must be something obvious, but I cannot find the error. Using mongo 3.4 from the shell client

like image 818
RafaelCaballero Avatar asked Dec 06 '16 18:12

RafaelCaballero


1 Answers

here is an example for your reference

db.inventory.aggregate(
   [
     {
       $project:
          {
            qty: { $gte: [ "$qty", 250 ] },

          }
     }
   ]
)

**

note : there is slight difference when you use aggregation framework when compared to the regular querying.

**

querying without aggregation framework

db.inventory.find( { qty: { $gte: 250 } } )

References:

https://docs.mongodb.com/manual/reference/operator/aggregation/gte/index.html

https://docs.mongodb.com/manual/reference/operator/query/gte/index.html

P.S: Other comparison operators also follow the same difference.

like image 163
satish chennupati Avatar answered Nov 02 '22 18:11

satish chennupati