[英]How to create multiple collections in mongodb?
I currently have a users collection.我目前有一个用户集合。 I want to create a logs collection and join them together.
我想创建一个日志集合并将它们连接在一起。 Right now I can create the users collection through.createCollection.
现在我可以通过.createCollection 创建用户集合。 But is it possible to create multiple collections in one go?
但是是否可以在一个 go 中创建多个 collections? Or do I have to do it through two separate.createCollection operations?
还是我必须通过两个单独的.createCollection 操作来完成?
To create a collection https://www.tutorialspoint.com/mongodb/mongodb_create_collection.htm创建集合https://www.tutorialspoint.com/mongodb/mongodb_create_collection.htm
To do a join https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/做一个加入https://docs.mongodb.com/manual/reference/operator/aggregation/lookup/
You can make a list of collection names and then loop through it and call db.createCollection
operations on mongo shell easily:您可以制作一个集合名称列表,然后遍历它并轻松调用
db.createCollection
对 mongo shell 的操作:
eg:例如:
> var collectionList = ["A", "B"];
> collectionList.forEach(function(collectionName) {db.createCollection(collectionName)})
After completion of the above command, just check the list of all collections:完成上述命令后,只需查看所有 collections 的列表:
> show collections
A
B
For details about the create collection visit the official documentation createCollection有关创建集合的详细信息,请访问官方文档createCollection
And for reference to other collections, please check the documentation of DBRef其他 collections 参考请查看DBRef的文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.