在MongoDB中克隆集合 [英] Clone a collection in MongoDB

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

问题描述

我想克隆一个MongoDB集合,并用不同的名称将其保存在同一台服务器上.因此,例如,现在我有以下集合:demo1.categories,demo1.users和demo2.users.

I want to clone a MongoDB collection and save it on the same server with a different name. So for example right now I have the following collections: demo1.categories, demo1.users and demo2.users.

我想要一个与"demo1.categories"相同的"demo2.categories". (只是名字不同.)

I want to have a "demo2.categories" which is identical to "demo1.categories". (It just has a different name.)

推荐答案

再次 MongoDB文档可以解救

假设该集合实际上被命名为"demo1.categories":

assuming that the collection actually is named "demo1.categories":

db.demo1.categories.find().forEach( function(x){db.demo2.categories.insert(x)} );

这篇关于在MongoDB中克隆集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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