Querying MongoDB subdocuments without respecting key order

Querying MongoDB subdocuments without respecting key order

I want to query against a subdocument. The problem is, that MongoDB seems to respect the order of the object keys. So if I do the following query, I won't receive any results:

I want to query against a subdocument. The problem is, that MongoDB seems to respect the order of the object keys. So if I do the following query, I won't receive any results:

db.getCollection('test').find({docId:'tLDmtdeYuG9DiGGrL',optimizeParams:{"deviceType":"mobile","daytime":"night"}})

If I change the order of optimizeParams, I will get a result:

db.getCollection('test').find({docId:'tLDmtdeYuG9DiGGrL',optimizeParams:{"daytime":"night","deviceType":"mobile"}})

Now a soultion would be to use dot notation, but in this case, I will receive ALL documents which contains both keys. But I only want the documents that ONLY have both keys (no others):

db.getCollection('test').find({docId:'tLDmtdeYuG9DiGGrL',"optimizeParams.deviceType":"mobile","optimizeParams.daytime":"night"})

Is there a way how I can execute a query without respecting the key order?

mongodb

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

MongoDB Database and java applications

Enroll for free demo to acquire the best knowledge on the schema-less database from live industry experts through MongoDB training

Which is the Best MongoDB GUI?

Our MongoDB Online Training provide you to learn about MongoDB strategies with realty. Our MongoDB Online Training also includes live sessions, live Projects, and much

Improve the MongoDB Aggregation Framework

Our MongoDB Online Training provide you to learn about MongoDB strategies with realty. Our MongoDB Online Training also includes live sessions, live Projects, and much

MongoDB – Database, Collection, and Document

Our MongoDB Online Training provide you to learn about MongoDB strategies with realty. Our MongoDB Online Training also includes live sessions, live Projects, and much

MongoDB brings database product range under one cloudy roof

Enroll for free demo to acquire the best knowledge on the schema-less database from live industry experts through MongoDB training