$[] operator not working in 3.6.3

103 views
Skip to first unread message

maxime...@caldera.com

unread,
Apr 6, 2018, 10:46:58 PM4/6/18
to mongodb-user
Hi,

I was looking to use the "$[]" operator in an update statement with the mongodb community edition for debian.Here is the situation :

Collection a :
{ "_id" : ObjectId("5ac74fe36b5973701b9ec7f7"), "tutu" : [ 0, 1 ] }

> a.update({}, {$inc:{"tutu.$[]":1}})
WriteResult({
       
"nMatched" : 0,
       
"nUpserted" : 0,
       
"nModified" : 0,
       
"writeError" : {
               
"code" : 16837,
               
"errmsg" : "cannot use the part (tutu of tutu.$[]) to traverse the element ({tutu: [ 0.0, 1.0 ]})"
       
}
})


When I try the same thing in mongo 3.7.3, it works well. But the spec is written as a new feature in mongo 3.6 . Is this a mongo 3.6 bug or a mistyping in the documentation?

https://docs.mongodb.com/v3.6/reference/operator/update/positional-all/#up._S_[]

Wan Bachtiar

unread,
Apr 8, 2018, 8:21:01 PM4/8/18
to mongodb-user

Is this a mongo 3.6 bug or a mistyping in the documentation?

Hi Maxime,

I couldn’t replicate the problem that you’re seeing on MongoDB v3.6.3:

> db.a.insert({tutu:[0, 1]});
WriteResult({
  "nInserted": 1
})
> db.a.update({}, {$inc:{"tutu.$[]":1}})
WriteResult({
  "nMatched": 1,
  "nUpserted": 0,
  "nModified": 1
})
> db.a.find()
{"_id": ObjectId("5acaafba311a74ec454207a7"), "tutu": [1,2]}

Could you check whether you're using MongoDB v3.6.3 ? 

Regards,
Wan.

Maxime Alves

unread,
Apr 10, 2018, 3:17:35 AM4/10/18
to 'Wan Bachtiar' via mongodb-user
Hi,

I think it is a mongo 3.6 bug.

I installed 3.6.3 on debian stretch and ubuntu xenial with the mongodb community repositories.

Thanks,
Maxime
> --
> 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.com/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/68b255ca-0669-401b-a4d8-14a38829fbd3%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

maxime...@caldera.com

unread,
Apr 18, 2018, 4:50:52 AM4/18/18
to mongodb-user
Hi,

I tried with mongodb 3.6.4 from community repositories on debian, it's still not working. I'm gonna try with a clean install.

Thanks,
Maxime
> To unsubscribe from this group and stop receiving emails from it, send an email to mongodb-user+unsubscribe@googlegroups.com.

Neil Lunn

unread,
Apr 18, 2018, 5:03:10 AM4/18/18
to mongodb-user


On Wednesday, 18 April 2018 18:50:52 UTC+10, maxime...@caldera.com wrote:
Hi,

I tried with mongodb 3.6.4 from community repositories on debian, it's still not working. I'm gonna try with a clean install.

A clean install is probably the best way.At the very least you should verify the server version with `db.version()` from the mongo shell. The error message you reported does seem indicative of a server version which is actually prior to MongoDB 3.6. 
Reply all
Reply to author
Forward
0 new messages