2

I'm writing a application where the user can write json-code and store that json code with an Id and a Collection. In other words, they specify an Id, a Collection (string; [a-zA-Z0-9]) and a Data (json, can be anything that is valid json).

Up til now I've been using RavenDb for this, cause I thought a document-database would be perfect, but I've had some problems with querying.

One of the objects that needs to be stored and queried is the following:

{
    "network": "some_network",
    "names": ["name1","name2"],
    "data": {"values":[],"keys":[]}
}

This object should be stored with some Id that is either specified, or auto-generated (if null is given), and a Collection (must always be specified), and then I need to be able to query it based on Collection, network and a single name.

For instance, I have the code query('users', '{"network":"some_network","names":"name1"}'), and I need that code to return this object (and any other object that matches it).

Also, I'm ok with changing database, but the database needs to be able to run in-process (self-hosted), and to be able to run without admin-rights without installation (in other words, it can't bind to hostname/ip like wcf does).

How can I achieve something like this?

Matt Johnson-Pint
  • 230,703
  • 74
  • 448
  • 575
Alxandr
  • 12,345
  • 10
  • 59
  • 95
  • you're essentially running this query: session.Query().Where(x => x.network == "some_network" && x.names.Any(y => y == "name1")). I'm not sure what you are trying to do, but if you'll use the tools RavenDB comes with you should be fine. – synhershko Sep 12 '11 at 00:17
  • Yes, but the problem is that I have no knowledge of the object graph at compile-time. As said, the user makes the json, and can make it however he or she likes. – Alxandr Sep 12 '11 at 03:06
  • and who generates the queries? if that's the user again, have him use Linq. RavenDB will do the rest in terms of indexing. – synhershko Sep 12 '11 at 06:55
  • How can I use linq when there is no compiled class to use linq agains? – Alxandr Sep 12 '11 at 09:56
  • Raven used to support passing Linq queries as strings, but not anymore, sorry. You can use the REST API and have a UI build that for you based on user input. Essentially this is what the Client API Linq support does - queries are just Lucene syntax. So: "network:some_network AND names:name1" – synhershko Sep 12 '11 at 11:22

1 Answers1

4

I found the answer to this:

    public string Query(string dynIndexName, string query)
    {
        using (var session = store.OpenSession())
        {
            var q = new IndexQuery();
            q.Query = query;
            var result = session.Advanced.DatabaseCommands.Query("dynamic/" + dynIndexName, q, new string[0]);
            return "[" + String.Join(",", result.Results.Select(r => r.ToString())) + "]";
        }
    }

Before calling the Query-method I convert the json-query-object into a Lucene-query that looks like this: (network:"some_network" AND names:"name1"), and use that as a query-parameter to the database. The whole class for storing and retrieving can be found here: https://github.com/Alxandr/RunJS/blob/master/src/AddIns/Storage/StorageMbro.cs

Alxandr
  • 12,345
  • 10
  • 59
  • 95