How to insert equal objects or list of objects in MongoDB?

1

Example, I have the following JSON:

{
    Casa:'b32',
    integrantes:{
        pessoa: 'joao',
        pessoa: 'Maria',
        pessoa: 'Daniel'
    }
}

When inserting into the database it stays this way.

Apparently it is overwritten. I currently do this insertion through Delphi (), but the same occurs on the MongoDB console itself;

In Delphi:

oDoc: TMongoDocument;
oDoc.BeginObject('doc').Append(stringJson).EndObject;
collection.Insert(oDoc);

Is there any way to insert these duplicate objects into Json? I did not find anything in Mongo's documentation about this duplicity or insertion in this way.

    
asked by anonymous 29.06.2018 / 20:18

1 answer

2

I think what you want to do is include an array of the person object, the way it did it is including a property / person attribute and it really is only possible to have a property with the same name. To include multiple people the correct Json would be this below.

{
Casa:'b32',
integrantes:[
    {pessoa: 'joao'},
    {pessoa: 'Maria'},
    {pessoa: 'Daniel'}
 ]
}

Follow the example in the mongodb shell:

    
29.06.2018 / 21:12