Mongoose和aggregate $out

2hh7jdfx  于 9个月前  发布在  Go
关注(0)|答案(1)|浏览(112)

我在我的nodejs项目中使用mongoose。
如何在mongoose中将所有文档从集合A转移到集合B?集合A没有在mongoose中定义的模型,集合B有在mongoose中定义的模型。我尝试了以下方法,但没有复制任何内容:

await mongoose.connection.db
    .collection("collectionA")
    .aggregate([{ $out: "collectionB" }]);

字符串
我尝试在mongosh中复制以下查询:

db.collectionA.aggregate([{ $out: "collectionB" }]);

a2mppw5e

a2mppw5e1#

它没有在服务器上运行命令。在末尾添加.toArray():

await mongoose.connection.db
    .collection("collectionA")
    .aggregate([{ $out: "collectionB" }])
    .toArray();

字符串

相关问题