复制一个mongodb集合 [英] Duplicate a mongodb collection

查看:87
本文介绍了复制一个mongodb集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用C#在同一服务器上的Mongodb中复制集合的正确方法是什么? MongoVUE有一个选项重复收集",C#是否有类似的东西?

What is a proper way to duplicate a collection in Mongodb on the same server using C#? MongoVUE has an option 'Duplicate collection', is there something similar for C#?

推荐答案

没有使用C#驱动程序复制集合的内置方法,但是您仍然可以非常简单地执行以下操作:

There isn't a built-in way to copy collections with the C# driver, but you can still do it pretty simply as:

var source = db.GetCollection("test");
var dest = db.GetCollection("testcopy");
dest.InsertBatch(source.FindAll());

但是,请注意,这不会复制源集合中的任何索引. Shell的copyTo方法具有相同的局限性,因此实现起来可能类似.

Note, however, that this won't copy any indexes from the source collection. The shell's copyTo method has the same limitation so it's likely implemented similarly.

这篇关于复制一个mongodb集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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