- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
有没有办法更改 MongoDB 集合引用?对于变化,我指的是引用中的值。我不能只创建直接链接,因为数据库正在使用中。我的结构看起来像这样
{
"_id" : ObjectId("4e7c6b47e4b0dea06288ad21"),
"license" : "ABC123",
"model" : "911",
"make" : "Porsche",
"owner" : {
"$ref" : "users",
"$id" : "Test User"
}
}
我想改ID像
{ "$ref" : "users", "$id" : "NEW USER"}
最佳答案
当然可以,但不能直接使用 $set :
> db.test.save({a:{$ref:"users", $id:"Test User"}})
> db.test.find()
{ "_id" : ObjectId("4f1e85489d086ee4511551b6"), "a" : DBRef("users", "Test User") }
> db.test.update({}, {$set:{'a.$id':"NEW USER"}})
> db.test.find()
{ "_id" : ObjectId("4f1e85489d086ee4511551b6"), "a" : { "$id" : "NEW USER", "$ref" : "users" } }
如您所见,这会破坏引用,因为 DBRef 规范要求 $ref 和 $id 字段的顺序首先是 $ref。
你可以像这样更新它:
> db.test.update({}, {$set:{a:{$ref:"users", $id:"NEW USER"}}})
> db.test.find()
{ "_id" : ObjectId("4f1e858b9d086ee4511551b7"), "a" : DBRef("users", "NEW USER") }
或者,如果您在 shell 中,则只使用“new DBRef(..)”。
关于json - MongoDB 更改 DBrefs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8985039/
在 Mongoose 中, 我可以声明模式并且我也可以使用 DBRef 这只是简单地放置ObjectId或ObjectId数组 并填充(获取)这些项目。 我认为当需要删除 DBRef 时会出现问题。
我有以下 2 个模式: 公司事件: var companyEventSchema = new Schema({ name : String, description date
当我尝试在 mongo ruby 驱动程序中使用 DBRef(创建一个新的 DBRef 对象并包含在我插入到集合中的文档中)时,我收到此错误,我无法做出正面或反面的信息: NoMethodErro
我知道在 MongoDB 中可以对另一个文档的引用进行非规范化。通过非规范化,我的意思是选择在引用(持有)文档中提及哪些字段,除了引用文档的 id 之外。 我在SpringData中找到了@DBRef
我对 mongodb 的了解还不够。但在搜索 DbRef 和手动引用之后,我得出了我们应该避免 DbRef 的结果。 DbRef 发出额外的请求来加载数据,但相同的条件适用于手动引用 - 我们将进行额
我正在将 Mongo 与 Spring Data 结合使用。 我有两个(一流的)实体 (@Documents) Entity1 和 Entity2,其中 Entity1 在其中有一个 Entity2
我在使用 MongoDB 时遇到过几种需要使用 DBRef 的情况。但是,我还想在 DBRef 本身中缓存引用文档中的一些字段。 {$ref:'user', $id:'10285102912A', u
我有一个专为商店用户通知设计的类层次结构: @Document public class Notification { @Id private String id; @DBRef
使用 DBREF datatype在 MongoDB 中,文档可能如下所示。但是在每一行中都有 $ref 字段感觉是多余的,因为每一行显然都指向 users 集合。 有没有一种方法可以引用其他文档而不
在《MongoDB关系》一节中,为了在 MongoDB 中实现规范化的数据库结构,我们使用了引用式关系(也称为手动引用)的概念,在手动引用中,我们需要将被引用文档的 _id 存储在其他文档中。当文档中
我们正在开发一个读取量很大并且可能包含数百万个文档的应用程序。几乎每个集合我们都需要引用用户信息。用户信息具有一些可能不时更改的属性。 我们应该使用 DBref 还是将用户信息嵌入到所有集合中? 在大
解决方案可能就在我面前,但我还没有找到它。我的问题是我需要查找包含指定 DBRef 的所有文档。以下是要搜索的集合的结构: { "_id" : ObjectId("4e2d4892580fd6
我是 MongoDB 新手。在我的java代码中,我必须定义一个文档。此文档中的字段之一必须包含其他文档的 DBRef 数组。如何创建客户群?如何做呢?有哪些替代方案? @DBRef private
我的文档中有一个 map 字段(键=内容类型,值=内容),我希望将值部分(内容,这是另一个文档)作为引用对象保存在mongodb中。 private Map relatedContents; 例如,对
我有以下实体: class Linf { @Id ObjectId id; @Reference Denied denied; } 我想找到所有具有特定 id
在 Spring 项目中,我使用 Spring Data MongoDB,并且有 2 个类: public class ClassA { @Id private String id; private
我有一个包含元素的收集 session { "_id" : NumberLong(1), "_class" : "cws.CWSession", "title" : "java
我正在尝试使用 db.collections.insert 将初始数据加载到 mongodb。我有一个案例,我将插入城镇集合,然后插入邮政编码集合。邮政编码集合是指城镇集合。但是,当我编写脚本时,我不
有没有办法更改 MongoDB 集合引用?对于变化,我指的是引用中的值。我不能只创建直接链接,因为数据库正在使用中。我的结构看起来像这样 { "_id" : ObjectId("4e7
出于测试目的,我需要在 MongoDB 中手动创建一些对象。我的类(class)有一个到另一个类(class)的引用字段。引用的对象已经存在。 我试图将现有对象的 Mongo-ID 作为值放入新对象中
我是一名优秀的程序员,十分优秀!