将集合中的少数文档复制到mongo DB中的另一个集合

时间:2023-01-03 02:57:35

I have two collections , one where all documents are stored and the other where the documents will be stored after processing. I am new with mongo and would like to know if there is any method to copy the documents from one collection to the other ?

我有两个集合,一个集合存储所有文档,另一个集合在处理后存储文档。我是mongo的新手,想知道是否有任何方法可以将文件从一个集合复制到另一个集合中?

2 个解决方案

#1


2  

Try this:

db.firstColllection.aggregate([
    {$limit: 10},
    {$out: "secondCollection"}
])

#2


0  

To copy all files, we can use db.source.copyTo("target") as well

要复制所有文件,我们也可以使用db.source.copyTo(“target”)

#1


2  

Try this:

db.firstColllection.aggregate([
    {$limit: 10},
    {$out: "secondCollection"}
])

#2


0  

To copy all files, we can use db.source.copyTo("target") as well

要复制所有文件,我们也可以使用db.source.copyTo(“target”)