RavenDb 存储和检索无类对象 (json)

发布于 2024-12-04 05:08:45 字数 698 浏览 0 评论 0原文

我正在编写一个应用程序,用户可以在其中编写 json 代码并使用 Id 和 Collection 存储该 json 代码。换句话说,它们指定一个 Id、一个 Collection(字符串;[a-zA-Z0-9])和一个 Data(json,可以是任何有效的 json)。

到目前为止,我一直在使用 RavenDb,因为我认为文档数据库是完美的,但我在查询方面遇到了一些问题。

需要存储和查询的对象之一如下:

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

该对象应该与指定的或自动生成的一些 Id 一起存储(如果给出 null ),以及一个 Collection (必须始终指定),然后我需要能够基于集合、网络和单个名称来查询它。

例如,我有代码 query('users', '{"network":"some_network","names":"name1"}'),我需要该代码来返回此对象(以及与其匹配的任何其他对象)。

另外,我可以更改数据库,但是数据库需要能够在进程中运行(自托管),并且能够在没有管理员权限的情况下运行而无需安装(换句话说,它不能绑定像 wcf 一样到主机名/IP)。

我怎样才能实现这样的目标?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掐死时间 2024-12-11 05:08:45

我找到了答案:

    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())) + "]";
        }
    }

在调用查询方法之前,我将 json-query-object 转换为 Lucene 查询,如下所示:(network:"some_network" AND names:"name1"),并将其用作数据库的查询参数。用于存储和检索的整个类可以在这里找到: https ://github.com/Alxandr/RunJS/blob/master/src/AddIns/Storage/StorageMbro.cs

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文