2016-05-03 122 views
1

我在Ubuntu虚拟机上使用MongoDB和Mongochef GUI。我需要做一个查询插入我以前找到的数据。查找查询后MongoDB插入数据

我该怎么做?我认为是这样的:

db.createCollection("prueba", { capped : true, size : 5242880, max : 5000 }) 
db.gmap.find({ emotion: 1 }) 
db.prueba.insertMany(db.gmap.find({ emotion: 1 })) 

GMAP是我有的其他集合,查找查询返回所需的数据。 感谢

回答

2

要解决,我们需要存储结果作为数组,然后插入 - 请找片断如下:

var a = db.sourceCollection.find().toArray() 
db.destinatioCollection.insert(a) 
+0

解决。非常感谢! – aserrin55

0

排除某些字段使用发现投影选项:本例中的“ _id“字段被排除,有用的插入到相同的集合中。

要插入许多文件使用insertMany方法:

db.dstColl.insertMany(db.srcColl.find({}, {"_id": false}).toArray())