OrientDB:按整个嵌入字段值过滤

问题描述 投票:1回答:1

我要在OrientDB中插入带有嵌入字段的记录,然后使用过滤器查询该记录:

insert into MyClass set embeddedField = {'@type': 'd', 'id': 1}

效果很好,而且

select from MyClass

返回我添加的记录。但是当我为embeddedField添加过滤器的地方时,我得不到任何结果:

select from MyClass where embdeddedField = {'@type': 'd', 'id': 1}

我认为可能会发生这种情况,因为Orient将@version字段添加到嵌入式文档中,因此我尝试使用版本进行搜索:

select from MyClass where embdeddedField = {'@type': 'd', '@version': 0, 'id': 1}

但仍然没有结果。

问题:有没有想过如何通过整个文档过滤嵌入字段?无需嵌入文档的每个字段显式过滤:

select from MyClass
where embdeddedField.id = 1 
and embdeddedField.field2 = val2
and embeddedField.field3 = val3

因为有几个原因我想将整个对象作为单个查询参数传递:

select from MyClass where embdeddedField = ?
orientdb orientdb3.0
1个回答
0
投票

那是因为提供的Hash被转换为嵌入式类。

也许看看ActiveOrientWiki https://github.com/topofocus/active-orient/wiki/Relations

要解释一下:拿一个类base,有一个带有两个属性的文档(无模式)并向其中添加现有文档

( 0..9 ).each do | b |
    base_record= Base.create label: b, first_list: []
    ( 0..9 ).each {|c| base_record.first_list << FirstList.create( label: c ) }
 end
INFO->CREATE VERTEX base CONTENT {"label":0,"first_list":[]}
INFO->CREATE VERTEX first_list CONTENT {"label":0}
INFO->update #136:0 set first_list = first_list || [#147:0]   return after @this

然后嵌入链接并且记录看起来像

 => #<Base:0x00000000041a60e0 @metadata={:type=>"d", :class=>"base", :version=>11, :fieldTypes=>"first_list=z", :cluster=>129, :record=>1},
 @attributes={:first_list=>["#149:1", "#150:1", "#151:1", "#152:1", "#145:2", "#146:2", "#147:2", "#148:2", "#149:2", "#150:2"], :label=>"1"}> 

如果展开列表项,则可以查询“@type”

如果添加一个没有删除的文档,则会发生同样的事情

( 0..9 ).each {|c| base_record.first_list << FirstList.new( label: c ) }
20.04.(12:53:59) INFO->update #130:2 set first_list = first_list || [{ @type: 'd' ,@class: 'first_list' ,label: 0 }]   return after @this

INFO->CREATE VERTEX base CONTENT {"label":"c","first_list":[]}
'#130:2'.expand
 => #<Base:0x00000000043927a0 @metadata={:type=>"d", :class=>"base", :version=>11, :fieldTypes=>"first_list=z", :cluster=>130, :record=>2}, 
 @attributes={:first_list=>["#151:12", "#152:12", "#145:13", "#146:13", "#147:13", "#148:13", "#149:13", "#150:13", "#151:13", "#152:13"], :label=>"c"}>

如果省略类名,则只有rid的范围发生变化

INFO-> update #132:2 set first_list = first_list || { @type: 'd'  ,label: 0 }   return after @this
 => [#<Base:0x0000000003a26fb8 @metadata={:type=>"d", :class=>"base", :version=>3, :fieldTypes=>"first_list=z", :cluster=>132, :record=>2}, 
@attributes={:first_list=>["#3:0"], :label=>"d"}>] 

在任何情况下,查询qazxsw poi文件

© www.soinside.com 2019 - 2024. All rights reserved.