$arrayElemAt throwing invalid operator error in 3.2.4

770 views
Skip to first unread message

epice...@gmail.com

unread,
Mar 18, 2016, 11:43:49 PM3/18/16
to mongodb-user, mi...@vicino.io
Hi, I'm running mongodb 3.2.4 on the latest version of El Capitan. I'm trying to write an aggregation pipeline that uses the new $arrayElemAt operator in the $projection phase. However, I keep getting an error that states: E QUERY  [thread1] Error: command failed: 
{ "errmsg" : "exception: invalid operator '$arrayElemAt'", "code" : 15999, "ok" : 0 }.

I've even tried copying and pasting the exact example from the docs, but get the same error. So pretty sure it's not a syntax error. 



Asya Kamsky

unread,
Mar 19, 2016, 3:09:13 AM3/19/16
to mongodb-user
I'm pretty sure I don't believe that it's not a syntax error unless you cut and paste the exact output of the following:

db.version()
your full pipeline.

I use the $arrayElemAt expression pretty much all the time and I can promise you it works (on my Mac even).

Asya
P.S. heck, it was still in my scrollback, and it's the exact same version of mongod - 3.2.4:
test@local:27017(3.2.4) > db.went.aggregate({$sort:{name:1,dateTimeSeen:1}}, {$group:{_id:"$name", places:{$push:{place:"$placeSeen",time:"$dateTimeSeen"}}}},{$project:{trips:"$places",places:1}},{$unwind:"$places"},{$sort:{name:1,time:1}},{$project:{"places":1, to: {$arrayElemAt:[ {$filter:{input:"$trips",as:"trip",cond:{$and:[{$ne:["$places.place","$$trip.place"]},{$lt:["$places.time","$$trip.time"]}]}}},0]}}}, {$match:{to:{$ne:null}}} )
{ "_id" : "Sue", "places" : { "place" : "B1", "time" : ISODate("2016-03-16T10:21:41Z") }, "to" : { "place" : "A1", "time" : ISODate("2016-03-16T10:24:41Z") } }
{ "_id" : "Sue", "places" : { "place" : "A1", "time" : ISODate("2016-03-16T10:24:41Z") }, "to" : { "place" : "C1", "time" : ISODate("2016-03-16T10:29:41Z") } }
{ "_id" : "Sue", "places" : { "place" : "C1", "time" : ISODate("2016-03-16T10:29:41Z") }, "to" : { "place" : "B1", "time" : ISODate("2016-03-16T10:35:00Z") } }
{ "_id" : "John", "places" : { "place" : "A1", "time" : ISODate("2016-03-16T10:25:41Z") }, "to" : { "place" : "B1", "time" : ISODate("2016-03-16T10:27:41Z") } }
{ "_id" : "John", "places" : { "place" : "B1", "time" : ISODate("2016-03-16T10:27:41Z") }, "to" : { "place" : "C1", "time" : ISODate("2016-03-16T10:29:41Z") } }


--
You received this message because you are subscribed to the Google Groups "mongodb-user"
group.
 
For other MongoDB technical support options, see: https://docs.mongodb.org/manual/support/
---
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user...@googlegroups.com.
To post to this group, send email to mongod...@googlegroups.com.
Visit this group at https://groups.google.com/group/mongodb-user.
To view this discussion on the web visit https://groups.google.com/d/msgid/mongodb-user/b79acd4d-8c82-4514-a234-13ef14ae89b0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Asya Kamsky
Lead Product Manager
MongoDB
Download MongoDB - mongodb.org/downloads
Free MongoDB Monitoring - cloud.mongodb.com
Free Online Education - university.mongodb.com
Get Involved - mongodb.org/community
We're Hiring! - https://www.mongodb.com/careers
Reply all
Reply to author
Forward
0 new messages