Daisy Rees

Daisy Rees

1550110872

Embedded symbols in MongoDB

I am new to querying MongoDB but am running into difficulty filtering Objects where certain symbols exist. For example:

I have a number Objects in my collection engine that are structured like this:

{
    "_id" : ObjectId("5c3a5efa6b0526729490cb2f"),
    "imsi" : "12345",
    "class_name" : "foo",
    "decoded_payload" : {
        "timestamp" : 1547329260,
        "lock_status" : "LOCKED"
    },
    "direction" : "in",
    "created_at" : ISODate("2019-01-12T21:41:14.998Z")
}

My objective is to get Objects whose imsi is 12345 that contain a decoded_payload that contains lock_status (lock status is of type symbol, not string). Many objects do not contain these keys so I want to filter out the ones that do.

The query runs, but returns zero results (although there are many Objects that should be returned). I am wondering if there is a syntax error that is overlooked because lock_status is of type symbol. What could be the error here?

My query:

db.getCollection('engine').find({

$and: [

{"decoded_payload":{
$exists: true,
$elemMatch: {"lock_status":{$exists:true} } 
    }
},

{"imsi": "12345"}


]})

.sort({“decoded_payload.timestamp”:-1})


#mongodb #sql

What is GEEK

Buddha Community

Query of MongoDB | MongoDB Command | MongoDB | Asp.Net Core Mvc

https://youtu.be/FwUobnB5pv8

#mongodb tutorial #mongodb tutorial for beginners #mongodb database #mongodb with c# #mongodb with asp.net core #mongodb

Install MongoDB Database | MongoDB | Asp.Net Core Mvc

#MongoDB
#Aspdotnetexplorer

https://youtu.be/cnwNWzcw3NM

#mongodb #mongodb database #mongodb with c# #mongodb with asp.net core #mongodb tutorial for beginners #mongodb tutorial

Insert & Save method in MongoDB | Inserting Document | CRUD Operation in MongoDB

#MongoDB
#AspDotNetExplorer
https://youtu.be/CohnNdE_rjM

#mongodb #mongodb tutorial for beginners #mongodb tutorial #mongodb database #learn mongodb

Execute MongoDB Command | Create, Drop and Select Database | MongoDB | Asp.Net Core Mvc

https://youtu.be/SKpNG83X2Ig

#mongodb #mongodb with asp.net core #mongodb with c# #mongodb tutorial for beginners #mongodb tutorial #learn mognodb

MongoDB Delete Document | Remove, DeleteOne and DeleteMany Methods | Asp.Net Core

https://youtu.be/l7m7lApock4

#crud operation #mongodb #mongodb tutorial for beginners #mongodb tutorial #mongodb database #learn mongodb