So if I for example have in my db:
[
{
"_id":"someid",
"Emails" : {
"anotherId" : {
"Email" : "a...@a.com"
}
}
},
{
"_id":"someid2",
"Emails" : {
"anotherId2" : {
"Email" : "b...@b.com"
}
}
}
]
How would I search for any records having "b...@b.com" as any email
within its Emails object (i.e. return the second one :P )?
--
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.
Hi,
Sorry, I meant that I wouldn't know the anotherId. I just want to
search for any document that has that b...@b.com in any object under
Emails, so it could look like this, and I could find the second
document only:
[
{
"_id":"someid",
"Emails" : {
"anotherIdblahblah" : {
"Email" : "a...@a.com"
}
"unknownId" : {
"Email" : "c...@c.com"
}
}
},
{
"_id":"someid2",
"Emails" : {
"WhatIsThisId" : {
"Email" : "b...@b.com"
}
"IDontKnowThisId" : {
"Email" : "d...@d.com"
}
}
}
]
Cheers
Emails: [
{id: "...", email:"..."}
]
--
So I'm guessing the slow way would be to use JS and $where, would it?
> Store the otherid along with the email in the array value.
What would be the solution then? I don't care about the otherid btw.
--
I meant I don't care about retrieving it along with the email. It's
just an md5 of the email string in this case.
> If it really is not possible to change the schema you can use an MR or
> possibly the $where clause but yes they would be insanely slow depending on
> the size of your document and the number of documents within the constricted
> query and how often it is being queried. Both methods are of course not
> advised but personally I would prolly go with $where adding a JS function to
> it.
Usually there'll be one or two emails per document - but potentially
ludicrous amounts of documents... erkk...
So the calculation time wouldn't be THAT much more than doing a
standard query I guess...
although it would be nm where n is number of documents and m is number
of emails - m would average perhaps around 1.
Mostly it'll be 0 and occasionally it'll be 2 - rarely will it be more.
--
Person = { Name:"fred", Address: { type: "us", City: "Seatttle", Zip: 98125 }}