How's the mongodb collection getting the data in shape?



  • [
    key : {
         value1 : '123',
         value2 : '123'
        }
    ]
    

    instead

    [ 
    

    {
    value1 : '123',
    value2 : '123'
    }
    ]



  • You're getting a bad json:

    [
    key : {
         value1 : '123',
         value2 : '123'
        }
    ]
    

    I'm guessing we need to get this mass:

    [
        {
            "key" : {
                "value1" : "123",
                "value2" : "123"
            }
        }
    ]
    

    Then you can use it. https://docs.mongodb.com/manual/reference/method/cursor.map/ :

    db.test.insert({value1: '123', value2: '123'})
    db.test.find().map(function(e) {return {key: e};}
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2