Backports #3397 to 3.1.0-stable branch

We got bit by this as well in an embedded document `where`.