English 中文(简体)
MOngoDB - 如何找到其他收藏中的文档未引用的所有文件?
原标题:MongoDB - how can I find all documents that aren t referenced by a document from another collection
  • 时间:2012-05-23 02:36:40
  •  标签:
  • mongodb

这就是问题所在:

收藏 A 中有我的文件, 当它刚创建时, 它没有被任何其他文件引用 。 在某个时刻, 将创建收藏 B 中的文档, 并将在收藏 A 中引用文档的“ 对象 ” 。

在收藏A中找到我的文件没有在收藏B中引用的所有文件的最佳方式是什么?

我理解MongoDB不支持加入, 但我想知道除了从收藏 B 获取所有引用对象和在收藏 A 中找到不属于该清单的文件之外, 是否还有其他办法解决这个问题, 因为这个办法可能无法很好地推广。

我能不能将A集的文件嵌入B集的文件,然后将其从A集中删除?这是最好的解决办法吗?

谢谢你的帮助和评论

最佳回答

许多选项 :

(1) 将 B 文档的代号添加到 A 文档中的数组( 反向引用) 中。 现在, 您可以查找一个在该数组中没有元素的文档。 问题: 如果有大量交叉引用, 数组可能会变得太大, 无法显示文档的大小 。

(2) 添加一个收藏 C, 以跟踪 A s 和 B s 之间的引用。 行为像一个组合表格 。

3) 在 A 引用中有一个简单的旗帜。当您添加一个 B 标记它所引用的全部 A 符号时 。当您删除 B 时,扫描 B 扫描它所引用的所有 A 符号,并卸下不再有引用的 A 标记。 问题: 可能脱离同步 。

(4) 在 B 上使用地图缩放来创建一个收藏库,其中含有任何 B 所引用的所有 A 秒的代号。 使用该收藏来标记所有被引用的 A 秒( 之后先去除所有标记) 。 可以使用此收藏来定期修正 (3) 。

5) 在同一收集和使用地图中将两种文件类型都放入一个缩放图中,以发送_id和国旗在A中标出或B中标出。在缩放步骤中,寻找在A中标出但未在B中标出的任何群体。

.

问题回答

由于没有合并,唯一的选择是一提到就提出:要么使用嵌入文件,要么放弃使用两部分查询。

它取决于您的执行, 但是在 A 中相应的文档中添加文档类型 B 听起来是最好的选择。 这样您就可以使用直截了当的查询( http:// www. mongodb. org/ display/ DOCS/Advancedurier# 高级Query-% 24 exploits " rel=“ nofollow” >$expences 操作员 ) 来检索 A 。 @ info: tooltip

A.find( { B: { $exists: false } })




相关问题
Access DB Ref MongoDB

Whats the best way to access/query a DB Ref: UPDATE: users: name, groupref : {$ref:"groups",$id:"ObjectId ..." } } groups: name, topic, country,...,.. Assumption is that user belongs to only one ...

MongoDB nested sets

What re the best practices to store nested sets (like trees of comments) in MongoDB? I mean, every comment can have a parent comment and children-comments (answers). Storing them like this: { ...

MongoMapper and migrations

I m building a Rails application using MongoDB as the back-end and MongoMapper as the ORM tool. Suppose in version 1, I define the following model: class SomeModel include MongoMapper::Document ...

MongoDB takes long for indexing

I have the following setup: Mac Pro with 2 GB of RAM (yes, not that much) MongoDB 1.1.3 64-bit 8 million entries in a single collection index for one field (integer) wanted Calling .ensureIndex(...) ...

Storing and accessing large amounts of data

My application creates pieces of data that, in xml, would look like this: <resource url="someurl"> <term> <name>somename</name> <frequency>somenumber</...

热门标签