Eduardo Asafe
Eduardo Asafe

Reputation: 139

Removing the index of a collection in mongoDB?

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.

Upvotes: 0

Views: 166

Answers (2)

seduardo
seduardo

Reputation: 704

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.

Upvotes: 0

nomDePlum
nomDePlum

Reputation: 101

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.

Upvotes: 1

Related Questions