> db.profiles.insert({"_id": 123, "createdById" : 3 , "legacyId" : 11420 , "otherId" : 1})
> db.profiles.update({'_id': 123}, {$push:{"newfield" : { "createdById" : 3 , "legacyId" : 11420 , "otherId": 11}}})
> db.profiles.update({'newfield.createdById': 3}, {$push:{"newfield.newnewfield" : { "createdById" : 3 , "legacyId" : 11420 , "otherId" : 11}}})
can't append to array using string field name [newnewfield]
I must be doing something stupid. Is this kind of functionality just
not supported by Mongo?
Thanks!
Chris
> --
> 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.
>
>
> db.profiles.findOne()
{
"_id" : 123,
"createdById" : 3,
"legacyId" : 11420,
"newfield" : [
{
"createdById" : 3,
"legacyId" : 11420,
"otherId" : 11
}
],
"otherId" : 1
}
Yes, you need to use the positional operator:
>db.profiles.update({'newfield.createdById': 3}, {$push:{"newfield.$.newnewfield" : { "createdById" : 3 , "legacyId" : 11420 , "otherId" : 11}}})
> db.profiles.findOne()
{
"_id" : 123,
"createdById" : 3,
"legacyId" : 11420,
"newfield" : [
{
"createdById" : 3,
"legacyId" : 11420,
"newnewfield" : [
{
"createdById" : 3,
"legacyId" : 11420,
"otherId" : 11
}
],
"otherId" : 11
}
],
"otherId" : 1
}
I doubt this is what you want, but it is the closest to what you have
described with your updates.
Can you provide the finished document you want?
Maybe this:
>db.profiles.update({'newfield.createdById': 3}, {$push:{"newfield.$" : { "createdById" : 3 , "legacyId" : 11420 , "otherId" : 11}}})
or this:
>db.profiles.update({'newfield.createdById': 3}, {$push:{"newnewfield" : { "createdById" : 3 , "legacyId" : 11420 , "otherId" : 11}}})
db.profiles.find({'newfield.createdById': 3})
But when each is its own document how could I do a query like that if
I want to search across all the newfields?
Thanks so much for the help,
Chris
db.profiles.update({'newfield.createdById': 3},
{$push:{"newfield.$.newnewfield" : { "createdById" : 3 , "legacyId" :
11420 , "otherId" : 11}}})
But now I want to insert one deeper but this doesn't work:
db.profiles.update({'newfield.newnewfield.createdById': 3},
{$push:{"newfield.newnewfield.$.deepercollection" : { "createdById" :
3 , "legacyId" : 11420 , "otherId" : 11}}})
I sense that I'm still misunderstanding the positional operator. But
the second case seems similar to the first. The first clause
identifies the document(s) i want updated and then the second says
where to put it. Is this possible?
Chris
Thanks a bunch,
Chris
Chris
Chris