mongodb转换为sql INSERT ... SELECT [英] mongodb translation for sql INSERT...SELECT

查看:126
本文介绍了mongodb转换为sql INSERT ... SELECT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果像{conditionB:1}这样的条件,如何简单地从collectionABC复制文档并将其复制到collectionB,并添加ts_imported这样的时间戳-不知道原始文档中包含的详细信息?

How to simply duplicate documents from collectionABC and copy them into collectionB if a condition like {conditionB:1} and add a timestamp like ts_imported - without knowing the details contained within the original documents?

我找不到与MySQL的INSERT ... SELECT ...

I could not find a simple equivalent for mongodb which is similar to mysql's INSERT ... SELECT ...

推荐答案

您可以使用mongoshell中的javascript实现类似的结果:

You can use javascript from mongoshell to achieve a similar result:

db.collectionABC.find({ conditionB: 1 }).
forEach( function(i) { 
  i.ts_imported = new Date();
  db.collectionB.insert(i);
});

这篇关于mongodb转换为sql INSERT ... SELECT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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