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

Asked

Viewed 647 times

1

Example, I have the following JSON:

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

When you enter it into the database it looks like this.

inserir a descrição da imagem aqui

Apparently it is overwritten. I currently do this insertion by Delphi(), but the same occurs in Mongodb’s own console;

At Delphi:

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

Is there any way to insert these duplicate objects into Json? I found nothing in Mongo’s documentation about this duplicity or insertion in this way.

1 answer

2


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

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

Follow example in mongodb shell: inserir a descrição da imagem aqui

Browser other questions tagged

You are not signed in. Login or sign up in order to post.