There is a document like this:
{
"_id" : ObjectId("591ec6ca277b295fa98a772b"),
"userId" : 10,
"appPrefs" : [
{
"type" : "navi",
"elements" : [
{
"name" : "apple",
"value" : "",
"updateTime" : NumberLong(1222222222)
},
{
"name" : "banana",
"value" : "",
"updateTime" : NumberLong(1222222222)
}
]
}
]
}
You may find that elements
is a collection and embedded in another collection appPrefs
.
I want to update the updateTime
if it's less than specific update time (for example 1300000000) and the userId = 10 &&type = navi && elements.name = apple
. Firstly I'm trying to match the element and write a query, but no item returned.
db.cname.find({"userId" : 10, "appPrefs":{$elemMatch: {type : "navi", "elements": {$elemMatch: {name : "apple"}}}}})
But no item returned. Could anyone help to check why it happened?
Thanks in advance.
Update the query as @Samip Suwal said.