mongodb - 在 MongoDB 中克隆一个集合

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

我想要一个与“demo1.categories”相同的“demo2.categories”。 (只是名称不同而已。)

最佳答案

又是 MongoDB documentation comes to the rescue

假设集合实际上被命名为“demo1.categories”:

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

https://stackoverflow.com/questions/8933307/

相关文章:

javascript - 如何获取在另一个模型中定义的 Mongoose 数据库的架构

mongodb - 从 Mongoose 模型中获取模式属性

date - 在MongoDB中按日期分组

node.js - Express.js 在 MEAN 堆栈中做了什么?

php - MongoDB 和 CodeIgniter

c# - 将字符串转换为 MongoDB BsonDocument

node.js - Meteor - collection.find() 总是返回所有字段

mongodb - 如何在 docker 容器中启动 mongodb shell?

node.js - 如何设置 useMongoClient (Mongoose 4.11.0)?

mongodb - Mongo,通过 id 列表查找