0

I have this object and query

Object

{
  _id: 1,
  name: 'John Smith',
  items: [{
     name: 'item 1',
     value: 'one',
     _id: 1
  },{
     name: 'item 2'
     value: 'two',
     _id: 2,
  }]
}

Query

Person.update({'items._id': 2}, {'$set': {
    'items.$.surname': 'new surname'

}}, function(err) { ...

I want that the new updated (key / value) to be setted on first position like this

,{
         surname: 'new surname',
         name: 'item 2'
         value: 'two',
         _id: 2,
      }

not like this

 ,{

             name: 'item 2',
             value: 'two',
             _id: 2,
             surname: 'new surname',

          }

So is there a solution,

Thanks in advance

user2285831
  • 419
  • 1
  • 5
  • 18

1 Answers1

0

As far as I know if you append a property to an object that wasn't previously there it will always be appended to the object. The only workaround is to set the surname in the object to start with.