Search code examples
mongodbmongodb-compass

Is there a way to prevent {} 1 Fields from being printed and print the inner value?


I am querying a mongodb using mongodb compass, and I cannot print the value in table form, it always prints {} 1 Fields..I want to print the value inside as a table. The same thing happens when i use mongoexport

Here is the original json structure

Here is the query structure

These are the results


Solution

  • You should use the aggregation pipeline, as I show you in the image below: enter image description here

    Another option is to use Robo3T (Ex Robomongo) with the following query:

    db.getCollection('test').aggregate([ { '$addFields': {'birthdayValue': '$formAnswer.birthday.value'}}, {'$project': {'_id': 0, 'roleID': 1, 'birthdayValue': 1}}])
    

    You will get something as this other image shows: enter image description here