|
I have this single document in a collection:
{
|
"_id" : ObjectId("5877e601fe632e1905fda30f"),
|
"created_at" : ISODate("2017-01-12T20:24:34.118Z"),
|
"updated_at" : ISODate("2017-01-12T20:24:34.118Z"),
|
"name" : "Creamfields 2017",
|
"description" : "Creamfields Festival returns",
|
"start_time" : ISODate("2017-08-24T12:00:00Z"),
|
"end_time" : ISODate("2017-08-25T22:00:00Z"),
|
"image_url" : "https://d31fr2pwly4c4s.cloudfront.net/c/9/f/901322_0_creamfields-2017_400.jpg",
|
"buy_link" : "http://www.skiddle.com/whats-on/Warrington/Creamfields/Creamfields-2017/12846418/",
|
"place" : {
|
"name" : "Creamfields",
|
"emails" : [ ],
|
"location" : {
|
"city" : "Warrington Cheshire",
|
"country" : "",
|
"latitude" : 53.3900441,
|
"longitude" : -2.5969501,
|
"street" : "daresbury",
|
"zip" : "WA4 4ar"
|
},
|
"category_list" : [ ]
|
},
|
"set_times" : [
|
{
|
"_id" : ObjectId("5877e603fe632e1905fda311"),
|
"votes" : {
|
"down" : [ ],
|
"up" : [
|
"auth0|57927335386cd38f6f7cd9a9"
|
]
|
},
|
"created_by" : {
|
"user_id" : "a",
|
"username" : "test123"
|
},
|
"rooms" : [
|
{
|
"name" : "Main",
|
"start_time" : ISODate("2017-08-24T12:00:00Z"),
|
"_id" : ObjectId("5877e603fe632e1905fda312"),
|
"artists" : [
|
{
|
"external_api_id" : "19SmlbABtI4bXz864MLqOS",
|
"image_url" : "https://i.scdn.co/image/10f32785a962f9aff1d217ad63aaada9394dd1e5",
|
"name" : "Carl Cox",
|
"end_time" : ISODate("2017-08-24T13:00:00Z"),
|
"start_time" : ISODate("2017-08-24T12:00:00Z"),
|
"_id" : ObjectId("5877e603fe632e1905fda313"),
|
"users_to_notify" : [ ],
|
"external_urls" : {
|
"spotify" : "https://open.spotify.com/artist/19SmlbABtI4bXz864MLqOS"
|
}
|
}
|
]
|
}
|
],
|
"test" : "abc"
|
},
|
{
|
"_id" : ObjectId("5877e612fe632e1905fda314"),
|
"votes" : {
|
"down" : [ ],
|
"up" : [
|
"auth0|57927335386cd38f6f7cd9a9"
|
]
|
},
|
"created_by" : {
|
"user_id" : "a",
|
"username" : "test123"
|
},
|
"rooms" : [
|
{
|
"name" : "Main ",
|
"start_time" : ISODate("2017-08-24T12:00:00Z"),
|
"_id" : ObjectId("5877e612fe632e1905fda315"),
|
"artists" : [
|
{
|
"external_api_id" : "1tRBmMtER4fGrzrt8O9VpS",
|
"image_url" : "https://i.scdn.co/image/7410105fbe41f6e262da552e61e0fe456477a47c",
|
"name" : "Hot Since 82",
|
"end_time" : ISODate("2017-08-24T13:00:00Z"),
|
"start_time" : ISODate("2017-08-24T12:00:00Z"),
|
"_id" : ObjectId("5877e612fe632e1905fda316"),
|
"users_to_notify" : [ ],
|
"external_urls" : {
|
"spotify" : "https://open.spotify.com/artist/1tRBmMtER4fGrzrt8O9VpS"
|
}
|
}
|
]
|
}
|
],
|
"test" : {
|
"created_by" : {
|
"user_id" : "a"
|
}
|
}
|
}
|
],
|
"created_by" : {
|
"sub" : "auth0|57927335386cd38f6f7cd9a9",
|
"username" : "test123"
|
},
|
"__v" : 0
|
}
|
Running this command produces the wrong result:
Command:
db.events.find({ "_id":ObjectId("5877e601fe632e1905fda30f"), "set_times._id": ObjectId("5877e612fe632e1905fda314"),"set_times.created_by.user_id": "a" }, { "set_times.$": 1 }).pretty()
|
{
|
"_id" : ObjectId("5877e601fe632e1905fda30f"),
|
"set_times" : [
|
{
|
"_id" : ObjectId("5877e603fe632e1905fda311"),
|
"votes" : {
|
"down" : [ ],
|
"up" : [
|
"auth0|57927335386cd38f6f7cd9a9"
|
]
|
},
|
"created_by" : {
|
"user_id" : "a",
|
"username" : "test123"
|
},
|
"rooms" : [
|
{
|
"name" : "Main",
|
"start_time" : ISODate("2017-08-24T12:00:00Z"),
|
"_id" : ObjectId("5877e603fe632e1905fda312"),
|
"artists" : [
|
{
|
"external_api_id" : "19SmlbABtI4bXz864MLqOS",
|
"image_url" : "https://i.scdn.co/image/10f32785a962f9aff1d217ad63aaada9394dd1e5",
|
"name" : "Carl Cox",
|
"end_time" : ISODate("2017-08-24T13:00:00Z"),
|
"start_time" : ISODate("2017-08-24T12:00:00Z"),
|
"_id" : ObjectId("5877e603fe632e1905fda313"),
|
"users_to_notify" : [ ],
|
"external_urls" : {
|
"spotify" : "https://open.spotify.com/artist/19SmlbABtI4bXz864MLqOS"
|
}
|
}
|
]
|
}
|
],
|
"test" : "abc"
|
}
|
]
|
}
|
Note the "set_times._id" values do not match. I think it has something to do with the "set_times.created_by.user_id" as if I remove this, it produces the correct document.
If I update the document:
db.events.update({}, { $set: { "set_times.0.created_by.user_id": "b" } })
|
And run the script again, it produces the correct result as the "set_times.created_by.user_id" values are different.
I am using MongoDb version 3.2
|