-1

I need to use find().pretty() to get the values for svalue and units but i am not sure how to write it correctly any help with syntax would be appreciated.

"IOT" : {
    "measurements" : {
        "meas_id" : "1",
        "sensor_id" : "223344",
        "svalue" : "22.3344",
        "units" : "DEG",
        "dt_measured" : "20190403T154653Z",
        "lat" : "533244",
        "long" : "60446.0"
    }
Shivam
  • 3,514
  • 2
  • 13
  • 27
MrGreen
  • 1
  • 1
  • possible duplicate - https://stackoverflow.com/questions/18277129/how-do-i-enable-mongodb-cli-pretty-print-db-col-find-pretty-not-working – Naga Sai A Apr 24 '19 at 17:45
  • Im only looking for certain parts of the collection is that similar? sorry new to mongo – MrGreen Apr 24 '19 at 17:57
  • https://stackoverflow.com/questions/3985214/retrieve-only-the-queried-element-in-an-object-array-in-mongodb-collection – Naga Sai A Apr 24 '19 at 18:03

2 Answers2

0

You can do something like this

db.<table_name>.find({},{"IOT.measurements.svalue":"","IOT.measurements.units":""}).pretty()

This will return svalue and units along with _id only. if you dont want _id u can set _id:false. Like this

  db.<table_name>.find({},{_id:false,"IOT.measurements.svalue":"","IOT.measurements.units":""}).pretty()
Shivam
  • 3,514
  • 2
  • 13
  • 27
  • Thank you for the response!, for my case db.measurements.find({},{IOT.measurements.svalue:"",IOT.measurements.units:""}).pretty() should be correct? This gives me a syntax error – MrGreen Apr 24 '19 at 18:14
  • can u post a screenshot or copy paste where exactly are u getting error – Shivam Apr 24 '19 at 18:29
  • db.measurements.find({},{IOT.measurements.svalue:"",IOT.measurements.units:""}).pretty() 2019-04-24T19:30:22.976+0100 E QUERY [js] SyntaxError: missing : after property id @(shell):1:28 – MrGreen Apr 24 '19 at 18:32
0

To achieve expected result, use below option of find and use '0' to exclude column and '1' to include columns in output

db.measurements.find({},{"IOT.measurements.svalue":1,"IOT.measurements.units":1}).pretty()
Naga Sai A
  • 10,771
  • 1
  • 21
  • 40