Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7803101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:27:53+00:00 2026-06-02T01:27:53+00:00

More specifically in Raven DB, I want to create a generic method with a

  • 0

More specifically in Raven DB, I want to create a generic method with a signature like;

public void Clear<T>() {...

Then have Raven DB clear all documents of the given type.

I understand from other posts by Ayende to similar questions that you’d need an index in place to do this as a batch.

I think this would involve creating an index that maps each document type – this seems like a lot of work.

Does anyone know an efficient way of creating a method like the above that will do a set delete directly in the database?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:27:55+00:00Added an answer on June 2, 2026 at 1:27 am

    After much experimentation I found the answer to be quite simple, although far from obvious;

    public void Clear<T>()
    {
        session.Advanced.DocumentStore.DatabaseCommands.PutIndex(indexName, new IndexDefinitionBuilder<T>
        {
            Map = documents => documents.Select(entity => new {})
        });
    
        session.Advanced.DatabaseCommands.DeleteByIndex(indexName, new IndexQuery());
    }
    

    Of course you almost certainly wouldn’t define your index and do your delete in one go, I’ve put this as a single method for the sake of brevity.

    My own implementation defines the indexes on application start as recommended by the documentation.

    If you wanted to use this approach to actually index a property of T then you would need to constrain T. For example if I have an IEntity that all my document classes inherit from and this class specifies a property Id. Then a ‘where T : IEntity’ would allow you to use that property in the index.

    It’s been said in other places, but it’s also worth noting that once you define a static index Raven will probably use it, this can cause your queries to seemingly not return data that you’ve inserted:

    RavenDB Saving to disk query

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

More specifically, I would like to automatically clear the workspace and all functions before
More specifically, if I have: public class TempClass : TempInterface { int TempInterface.TempProperty {
I have a file (more specifically, a log4j configuration file) and I want to
More specifically I want to test whether Oracle ODP.Net is installed on a machine.
More specifically, does NDK have a complete STL implementation. We're looking at this for
...or more specifically, how are they able to create animations via javascript, which is
http://developer.yahoo.com/yui/button More specifically, I want radio buttons. that can be checked/unchecked.
More specifically, for a random class with two public properties, in C# you can
More specifically, does CL require the user to have a data connection? Or is
More specifically, I have (simplified) the following: union foo { volatile int bits; char

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.