0

I would like to write some C# code that is called from a job in sitecore, which basically prunes all our mongodb data that is older than 1 year old. What is the exact C# code for doing that? I want to delete just the data, not drop any "databases". Do I need any specific assemblies/packages? Would I be cleaning out just our collection*.wt and index*.wt files for that?

Also, there's two parts to this; one is removing data that's older than a year old, and one is archiving that same data. I would like to export ALL data in mongodb older than a year into some .CSV or excel backup file (before deleting it from mongodb). What's the exact C# code for that? Can it only be done somehow using http://www.fourthbottle.com/2015/08/mongoexport-in-mongodb.html ? If so, what would be the command for exporting ALL data into a .CSV file, not just a specific collection?

Thanks!

user3034243
  • 145
  • 1
  • 9

1 Answers1

2

Try this:

collection.Remove(Query.EQ("CreatedOn", DateTime.Now.AddYears(-1)));
wp78de
  • 18,207
  • 7
  • 43
  • 71
  • Thanks! My other questions were, what assemblies/packages do I need for this, and what's the best/most efficient way of archiving and how is that done via C# code? Thanks again for your help! – user3034243 Oct 30 '17 at 15:43
  • Yes, please provide the exact C# code for the backup as well. He wants you to do his job for him, he doesn't want to have to read or learn anything. – ch1pn3ss Feb 08 '18 at 14:31