如何在temp db中存储查询输出? [英] How to store query output in temp db?

查看:138
本文介绍了如何在temp db中存储查询输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的很喜欢编程,但我正在研究它。我有一个我不知道如何解决的问题。
我在mongoDB中收集了文档,我使用Elasticsearch查询字段。问题是我想将搜索的输出存储在mongoDB中,但是在不同的DB中。我知道我必须创建临时数据库,必须更新每个搜索结果。但是怎么做呢?或者给我文档阅读,所以我可以学习。我真的很感谢你的帮助!

解决方案

Mongo不支持temp集合。



在这里做一个典型的事情是不要将整个结果输出实际写入另一个数据库,因为Elasticsearch会执行自己的缓存,因此您将无需任何图层。



同样,由于IO的关注,通常写一个10k记录的结果集到Mongo或另一个DB通常是一个坏主意。



有关于您所谈论的内容的功能要求: https://jira.mongodb.org/browse / SERVER-3215 ,但尚未计划。



示例



您可以拥有



在此表格中,您将拥有如下文档:

  {关键字:['bok','mongodb']} 

每次你搜索并滚动浏览每个结果你可以在这个表中填写一个关键字字段的行,该关键字字段包含该搜索结果中的关键字。每个搜索结果列表将搜索每个搜索结果列表。这可能是最好将每个搜索结果流入MongoDB进入。我从来没有编程Python(虽然我想学习)所以在伪的一个例子:

  var elastic_results = [{'elasticresult'}]; 
foreach(elastic_results as result){
//拆分此结果中的短语,并创建一个关键字数组
db.results_collection.insert(array_formed_from_splitting_down_result); //让只是懒惰插入不需要批量或试图缩小数据量一次或任何,只需流入它
}

所以当你沿着你的结果,你基本上只是大量插入尽可能快地创建一个流输入到MongoDB。它可以做得很好。



然后,这应该给你一个可擦除的单词和语言动词列表来处理像MR和东西之类的东西来汇总关于它们的统计信息。 / p>

不知道越来越多关于你的情况,这是我最好的答案。



这不使用临时表概念,而是使您的数据永久性,因为您希望将Mongo用作进一步任务的存储引擎,因此它的声音很好。


I am really new to the programming but I am studying it. I have one problem which I don't know how to solve. I have collection of docs in mongoDB and I'm using Elasticsearch to query the fields. The problem is I want to store the output of search back in mongoDB but in different DB. I know that I have to create temporary DB which has to be updated with every search result. But how to do this? Or give me documentation to read so I could learn it. I will really appreciate your help!

解决方案

Mongo does not natively support "temp" collections.

A typical thing to do here is to not actually write the entire results output to another DB since that would be utterly pointless since Elasticsearch does its own caching as such you don't need any layer over the top.

As well, due to IO concerns it is normally a bad idea to write say a result set of 10k records to Mongo or another DB.

There is a feature request for what you talk of: https://jira.mongodb.org/browse/SERVER-3215 but no planning as of yet.

Example

You could have a table of results.

Within this table you would have a doc that looks like:

{keywords: ['bok', 'mongodb']}

Each time you search and scroll through each result item you would write a row to this table populating the keywords field with keywords from that search result. This would be per search result per search result list per search. It would probably be best to just stream each search result to MongoDB as they come in. I have never programmed Python (though I wish to learn) so an example in pseudo:

var elastic_results = [{'elasticresult'}];
foreach(elastic_results as result){
    //split down the phrases in this result and make a keywords array
    db.results_collection.insert(array_formed_from_splitting_down_result); // Lets just lazy insert no need for batch or trying to shrink the amount of data to one go or whatever, lets just stream it in.
}

So as you go along your results you basically just mass insert as fast a possible create a sort of "stream" of input to MongoDB. It can do this quite well.

This should then give you a shardable list of words and language verbs to process things like MRs on and stuff to aggregate statistics about them.

Without knowing more and more about your scenario this is pretty much my best answer.

This does not use the temp table concept but instead makes your data permanent which is fine by the sounds of it since you wish to use Mongo as a storage engine for further tasks.

这篇关于如何在temp db中存储查询输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆