setTo on nested fields

46 views
Skip to first unread message

Egor

unread,
Jun 9, 2012, 4:14:56 AM6/9/12
to rogue-users
Hello. I use rogue 1.8

When I try to execute a query:
User where(_.id eqs "userId") modify(_.clans.subfield(_.isAdmin) setTo
Full(true)) updateOne(WriteConcern.SAFE)

I get:
Cause: com.mongodb.MongoException: can't append to array using string
field name [isAdmin]

But with usual fields all is well.

What am I doing wrong?

Jason Liszka

unread,
Jun 9, 2012, 9:38:32 AM6/9/12
to rogue...@googlegroups.com, rogue-users
Looks like a mongo limitation around setting fields in an array of objects. Can you run your query in the mongo console directly to see if that's it?

User where(_.id eqs "userId") modify(_.clans.subfield(_.isAdmin) setTo
Full(true)) toString

will give you the shell command to run.

You'll probably have more luck setting the field on a single object in the array. Try

User where(_.id eqs "userId")
and (_.clans somecondition)
modify(_.clans.$.subfield(_.isAdmin) setTo
Full(true))

http://www.mongodb.org/display/DOCS/Updating#Updating-The%24positionaloperator

Egor

unread,
Jun 9, 2012, 11:07:32 AM6/9/12
to rogue-users
Yes. It's mongo limitation :( There is no way to multiple update
embedded documents.
But your solution works. Thanks.

On 9 июн, 20:38, Jason Liszka <jlis...@foursquare.com> wrote:
> Looks like a mongo limitation around setting fields in an array of objects. Can you run your query in the mongo console directly to see if that's it?
>
> User where(_.id eqs "userId") modify(_.clans.subfield(_.isAdmin) setTo
> Full(true)) toString
>
> will give you the shell command to run.
>
> You'll probably have more luck setting the field on a single object in the array. Try
>
> User where(_.id eqs "userId")
> and (_.clans somecondition)
> modify(_.clans.$.subfield(_.isAdmin) setTo
> Full(true))
>
> http://www.mongodb.org/display/DOCS/Updating#Updating-The%24positiona...
Reply all
Reply to author
Forward
0 new messages