【问题标题】:Remove field from collection in RavenDB Studio从 RavenDB Studio 的集合中删除字段
【发布时间】:2020-03-02 20:10:21
【问题描述】:

我正在尝试使用 RavenDB Studio 删除一个属性(我在寻求帮助的文档中添加了该属性,请参阅here)(我不小心将它们添加到错误的数据库集合中......)。

再一次,我被语法困住了。另外——我不敢相信直到现在还没有人打算这样做——至少激烈的谷歌搜索无法产生任何有用的东西。至少可以说,官方文档在这个主题上也很简洁。 旁白:为什么 RavenDB(可能还有其他 NoSQL DB)中的 DDL 如此繁琐?

我尝试了各种版本

from things  as t
update {
    delete t.field 
}

这些都不起作用,其中一些甚至无法编译。

【问题讨论】:

    标签: ravendb ravendb-studio


    【解决方案1】:

    使用修补 - 可以从 客户端 代码中以这种方式删除文档字段:

    单个文档:

    session.Advanced.Defer(new PatchCommandData(
        id: "yourDocumentID",
        changeVector: null,
        patch: new PatchRequest
        {
            Script = @"delete this.fieldToDelete"
        },
        patchIfMissing: null));
    
    session.SaveChanges();
    

    见:Patching - Removing Property


    多个文档:

    var operation = store
        .Operations
        .Send(new PatchByQueryOperation("from things update { delete this.field; }"));
    
    operation.WaitForCompletion();
    

    示例取自here


    对于 RQL,只需使用:

    from things 
    update { 
       delete this.field; 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-04-02
      • 2021-09-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-18
      • 1970-01-01
      相关资源
      最近更新 更多