[DOCS-7794] Comment on: "manual/reference/operator/aggregation/arrayElemAt.txt" Created: 03/May/16  Updated: 03/Nov/17  Resolved: 03/May/16

Status: Closed
Project: Documentation
Component/s: None
Affects Version/s: None
Fix Version/s: 01112017-cleanup

Type: Bug Priority: Major - P3
Reporter: Docs Collector User (Inactive) Assignee: Ravind Kumar (Inactive)
Resolution: Done Votes: 0
Labels: collector-298ba4e7
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

mac el capitan
MongoChef 3.5.1

Location: https://docs.mongodb.org/manual/reference/operator/aggregation/arrayElemAt/
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.11; rv:45.0) Gecko/20100101 Firefox/45.0
Referrer: https://qnalist.com/questions/6409410/mongodb-user-arrayelemat-throwing-invalid-operator-error-in-3-2-4
Screen Resolution: 1920 x 1200


Participants:
Days since reply: 7 years, 41 weeks, 1 day ago

 Description   

There is a bug ,
invalid operator '$arrayElemAt' on server ......
the full response is

{ "errmsg" : "exception: invalid operator '$arrayElemAt'", "code" : 15999, "ok": 0.0 }

same is happening with $slice



 Comments   
Comment by Ravind Kumar (Inactive) [ 03/May/16 ]

User reported they are using MongoDB v3.0.9 via mLab. The features noted in the ticket are not available outside of MongoDB 3.2.

Comment by Ravind Kumar (Inactive) [ 03/May/16 ]

Hello,

I could not reproduce the errors on MongoDB 3.2.4 using the Mongo Shell.

 
 db.foo.find()
{ "_id" : 1, "name" : "dave123", "favorites" : [ "chocolate", "cake", "butter", "apples" ] }
{ "_id" : 2, "name" : "li", "favorites" : [ "apples", "pudding", "pie" ] }
{ "_id" : 3, "name" : "ahn", "favorites" : [ "pears", "pecans", "chocolate", "cherries" ] }
{ "_id" : 4, "name" : "ty", "favorites" : [ "ice cream" ] }
> db.foo.aggregate([{ 
...     $project: 
...      { 
...         name: 1,
...         threeFavorites: { $slice: [ "$favorites", 3 ] } 
...      } 
...    }
... ])
{ "_id" : 1, "name" : "dave123", "threeFavorites" : [ "chocolate", "cake", "butter" ] }
{ "_id" : 2, "name" : "li", "threeFavorites" : [ "apples", "pudding", "pie" ] }
{ "_id" : 3, "name" : "ahn", "threeFavorites" : [ "pears", "pecans", "chocolate" ] }
{ "_id" : 4, "name" : "ty", "threeFavorites" : [ "ice cream" ] }
> db.foo.aggregate([{
...      $project:
...       {
...          name: 1,
...          first: { $arrayElemAt: [ "$favorites", 0 ] },
...          last: { $arrayElemAt: [ "$favorites", -1 ] }
...       }
...    }
... ])
{ "_id" : 1, "name" : "dave123", "first" : "chocolate", "last" : "apples" }
{ "_id" : 2, "name" : "li", "first" : "apples", "last" : "pie" }
{ "_id" : 3, "name" : "ahn", "first" : "pears", "last" : "cherries" }
{ "_id" : 4, "name" : "ty", "first" : "ice cream", "last" : "ice cream" }
> 

Can you provide an exact copy of your pipeline, as well as the output from find() for the target database?

Also, can you confirm what version of MongoDB you are running by running version() in the shell?

Please note that MongoChef is not a supported MongoDB product. For the purposes of troubleshooting, please use the Mongo Shell to connect directly to the MongoDB instance.

Generated at Thu Feb 08 07:55:01 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.