Skip to Main Content

ORDS, SODA & JSON in the Database

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Different result than MongoDB with $elemMatch on scalar

Franck PachotAug 9 2025

The following query yields a different result in MongoDB and its Oracle emulation (tested on 23.9.0.25.08).

I have the following documents:

ora> db.dccomics.find()

[
 {
   _id: ObjectId('689709653f69ce62e0c59f37'),
   contact: [
     { email: [ 'bruce@wayneenterprises.com', 'batman@batcave.com' ] }
   ]
 },
 {
   _id: ObjectId('689709653f69ce62e0c59f38'),
   contact: [ { email: 'alfred@wayneenterprises.com' } ]
 },
 {
   _id: ObjectId('689709653f69ce62e0c59f39'),
   contact: [ { email: [ 'catwoman@gotham.com' ] } ]
 }
]

This query returns all documents, including the one that has no array for “email”:

ora> db.dccomics.find({
      "contact.email": { $elemMatch: { $gte: "a" } }
    })

[
 {
   _id: ObjectId('689709653f69ce62e0c59f37'),
   contact: [
     { email: [ 'bruce@wayneenterprises.com', 'batman@batcave.com' ] }
   ]
 },
 {
   _id: ObjectId('689709653f69ce62e0c59f38'),
   contact: [ { email: 'alfred@wayneenterprises.com' } ]
 },
 {
   _id: ObjectId('689709653f69ce62e0c59f39'),
   contact: [ { email: [ 'catwoman@gotham.com' ] } ]
 }
]

The same in MongoDB returns only the two documents with an array:
https://mongoplayground.net/p/prTdRkXLYJm

The documentation says:

$elemMatch only matches array elements

Comments
Post Details
Added on Aug 9 2025
0 comments
110 views