how to split mongo DB document into multiple documents using compose transporter

351 views Asked by At

I had a document like below I need to send this document to elasticsearch as 3 documents with title contains each of array and I am using compose transporter to send my documents to elasticsearch. How can I achieve this?

{
    "_id" : ObjectId("5c6bb079d209fd4dd5b4d6ce"),
    "title" : [ 
        "ram", 
        "sham", 
        "bhim"
    ]
}

and my expected output in elasticsearch is like this with different ids

{
    "_id" : ObjectId("5c6bb079d209fd4dd5b4d6ce"),
    "title" : "ram"

}

{
    "_id" : ObjectId("5c6bb079d209fd4dd5b4d6ce"),
    "title" : "sham"

}
{
    "_id" : ObjectId("5c6bb079d209fd4dd5b4d6ce"),
    "title" : "bhim"

}
1

There are 1 answers

0
Rilwan On

You can use the below query to achieve it,

db.collectionName.aggregate([{"$unwind":"$title"}])

Thanks, Mohamed Rilwan