Re: [mongodb-user] Problem with updates and $ positional operator

91 views
Skip to first unread message
Message has been deleted

Michael Dirolf

unread,
Apr 26, 2010, 4:47:15 PM4/26/10
to mongod...@googlegroups.com
What version of MongoDB are you running? I think that this restriction
was lifted in the 1.1.x series (and the positional operator wasn't
added until 1.3.x IIRC). Should probably make sure you're using at
least 1.4

On Mon, Apr 26, 2010 at 11:31 AM, Steve Doublon
<sts.i...@googlemail.com> wrote:
> Hi all,
>
> I would appreciate any advice on this, I'm pretty new to Mongo:
>
> I'm having some problems with updating values in a list.
> I have documents in a collection like this:
>
> {
> "movie":"Pulp Fiction",
> "cast":["Samuel","John"]
> }
>
> {
> "movie":"Swordfish",
> "cast":["John","Hugh", Halle"]
> }
>
> with an index on the "cast" list.
>
> Then in all documents that have the name "John" I want to update the
> name to "John Travolta" using the positional operator $ on the cast
> list:
>
> db.movies.update({cast:"John"},{$set: {'cast.$':"John Travolta"}}
> false,true)
>
> What I'm getting with the index on "cast" is this error message:
> "E12010 can't $inc/$set an indexed field"
>
> (And the question arises, how can I update indexed fields?)
>
> But even when I remove the index it still does not work, only with a
> different message this time:
>
> "Modifier spec implies existence of an encapsulating object with a
> name that already represents a non-object, or is referenced in another
> $set clause"
>
> Would be happy to get an idea about what I'm getting wrong here...
>
> Thanks a lot,
> Steve
>
> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

Steffen S.

unread,
Apr 26, 2010, 4:51:08 PM4/26/10
to mongodb-user
I'm using 1.4.1 on Win7 64 bit.

And sorry for the double posting, I was having issues with my Google
Account setup :/
> > For more options, visit this group athttp://groups.google.com/group/mongodb-user?hl=en.
>
> --
> You received this message because you are subscribed to the Google Groups "mongodb-user" group.
> To post to this group, send email to mongod...@googlegroups.com.
> To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
> For more options, visit this group athttp://groups.google.com/group/mongodb-user?hl=en.

Michael Dirolf

unread,
Apr 26, 2010, 4:56:58 PM4/26/10
to mongod...@googlegroups.com
Can you try db.version() from the shell after getting that error?
Could be wrong but my guess is still that you're connecting to an old
version of the server...

Лоик

unread,
Apr 26, 2010, 5:01:34 PM4/26/10
to mongod...@googlegroups.com
Just to confirm, It works perfectly well with 1.4 (linux). The problem isn't in the query for sure.

Лоик

unread,
Apr 26, 2010, 5:06:45 PM4/26/10
to mongod...@googlegroups.com
Oh I forgot to add the index. Yep I confirm, with an index on a list, It doesn't work anymore.

> db.movies.update({cast:"Samuel"},{$set: {'cast.$':"Samuel L Jackson"}}, false, true)
can't append to array using string field name
> db.version()
1.4.0

Steffen S.

unread,
Apr 26, 2010, 5:09:23 PM4/26/10
to mongodb-user
Here's what the server says on startup

Mon Apr 26 23:01:41 Mongo DB : starting : pid = 0 port = 27017 dbpath
= /data/db
/ master = 0 slave = 0 64-bit
Mon Apr 26 23:01:41 db version v1.4.1, pdfile version 4.5
Mon Apr 26 23:01:41 git version:
5b29dec9707d50979c283057ca1b1572351eef9a
Mon Apr 26 23:01:41 sys info: windows (6, 0, 6002, 2, 'Service Pack
2') BOOST_LI
B_VERSION=1_39

(there's no other MongoDB server running)

On my other machine (same OS, DB version etc.) the update works with
no index on "cast"
but with index I get "can't append to array using string field name"
(as explained in my accidental double post
http://groups.google.com/group/mongodb-user/browse_thread/thread/c28bb8ecedd27bd0#)

Thanks a lot,
Steffen

Michael Dirolf

unread,
Apr 26, 2010, 5:13:07 PM4/26/10
to mongod...@googlegroups.com
On Mon, Apr 26, 2010 at 5:09 PM, Steffen S. <sts.i...@googlemail.com> wrote:
> Here's what the server says on startup
>
> Mon Apr 26 23:01:41 Mongo DB : starting : pid = 0 port = 27017 dbpath
> = /data/db
> / master = 0 slave = 0  64-bit
> Mon Apr 26 23:01:41 db version v1.4.1, pdfile version 4.5
> Mon Apr 26 23:01:41 git version:
> 5b29dec9707d50979c283057ca1b1572351eef9a
> Mon Apr 26 23:01:41 sys info: windows (6, 0, 6002, 2, 'Service Pack
> 2') BOOST_LI
> B_VERSION=1_39
>
> (there's no other MongoDB server running)
>
> On my other machine (same OS, DB version etc.) the update works with
> no index on "cast"
> but with index I get "can't append to array using string field name"
> (as explained in my accidental double post
> http://groups.google.com/group/mongodb-user/browse_thread/thread/c28bb8ecedd27bd0#)


It sounds like this might be a bug - feel free to file a jira for
this. As for the other errors you were seeing, still 99% sure that
it's a version issue (that error code doesn't even exist in the 1.4
source AFAICT).

Steffen S.

unread,
Apr 26, 2010, 5:35:19 PM4/26/10
to mongodb-user
OK, thanks.
Filed it in Jira: http://jira.mongodb.org/browse/SERVER-1055

For the other errors I'll check the DB version on my other machine at
the office tomorrow :)

Best,
Steffen

On 26 Apr., 23:13, Michael Dirolf <m...@10gen.com> wrote:
> On Mon, Apr 26, 2010 at 5:09 PM, Steffen S. <sts.indo...@googlemail.com> wrote:
> > Here's what the server says on startup
>
> > Mon Apr 26 23:01:41 Mongo DB : starting : pid = 0 port = 27017 dbpath
> > = /data/db
> > / master = 0 slave = 0  64-bit
> > Mon Apr 26 23:01:41 db version v1.4.1, pdfile version 4.5
> > Mon Apr 26 23:01:41 git version:
> > 5b29dec9707d50979c283057ca1b1572351eef9a
> > Mon Apr 26 23:01:41 sys info: windows (6, 0, 6002, 2, 'Service Pack
> > 2') BOOST_LI
> > B_VERSION=1_39
>
> > (there's no other MongoDB server running)
>
> > On my other machine (same OS, DB version etc.) the update works with
> > no index on "cast"
> > but with index I get "can't append to array using string field name"
> > (as explained in my accidental double post
> >http://groups.google.com/group/mongodb-user/browse_thread/thread/c28b...)
Reply all
Reply to author
Forward
0 new messages