0

I want to remove the id of my document in MongoDB.

I will put the document below:

{
    "_id" : ObjectId("54f2324671eb13650e8b4569"),
    "nome" : "Pr.Ademar Lourenço",
    "tweet" : "Jornal Águas Lindas: Prefeito Hildo se reúne com governador Rollemberg e prefeitos do Entorno http://t.co/PtVWIENdO4"
}

I want you to be like this:

{
    "nome" : "Pr.Ademar Lourenço",
    "tweet" : "Jornal Águas Lindas: Prefeito Hildo se reúne com governador Rollemberg e prefeitos do Entorno http://t.co/PtVWIENdO4"
}

The reason and I'll export this document to a .txt and treats it out of MongoDB.

Eduardo Asafe
  • 129
  • 2
  • 10

2 Answers2

1

You can use mongoexport to export data in either json or csv format. There is a --fields option to this utility that will let you define which specific fields to export

--fields nome,tweet

Adjusting the examples in the reference documentation: http://docs.mongodb.org/v2.2/reference/mongoexport/ to your example.

For JSON

mongoexport --db sales --collection contacts --fields nome,tweet --out contacts.json

For CSV

mongoexport --db users --collection contacts --fields nome,tweet --csv --out contacts.csv

Hopefully this gives you enough to export your data into the form you want.

nomDePlum
  • 101
  • 5
  • Thanks for answering nomDePlum, I exported the document without _id but it was only in .csv format. But .json format, from what I understand, you can not export without the _id. – Eduardo Asafe Mar 02 '15 at 02:43
  • Hi Eduardo I wasn't aware of this limitation of mongoexport when exporting to JSON. – nomDePlum Mar 02 '15 at 07:08
  • 1
    http://stackoverflow.com/questions/12976145/mongoexport-without-id-field has what looks like a reasonable solution. I haven't tried it but hopefully it works for you. – nomDePlum Mar 02 '15 at 07:16
0

you can make a query and remove the _id field in projection parameter, example:

db.tweets.find({}, {_id:0});

this will remove the column _id in response.

seduardo
  • 704
  • 6
  • 6
  • Thanks for answering seduardo, Research works well. But, I was wondering how I could export my document so that is in research. – Eduardo Asafe Mar 02 '15 at 02:49