要推送值,请使用save()和for循环。让我们创建一个包含文档的集合-
> for(var v=1; v<7; v++) { ... db.demo739.save({Name:"Chris",SubjectName:"MongoDB"}); ... } WriteResult({ "nInserted" : 1 })
在find()方法的帮助下显示集合中的所有文档-
> db.demo739.find();
这将产生以下输出-
{ "_id" : ObjectId("5ead6e7857bb72a10bcf0666"), "Name" : "Chris", "SubjectName" : "MongoDB" } { "_id" : ObjectId("5ead6e7857bb72a10bcf0667"), "Name" : "Chris", "SubjectName" : "MongoDB" } { "_id" : ObjectId("5ead6e7857bb72a10bcf0668"), "Name" : "Chris", "SubjectName" : "MongoDB" } { "_id" : ObjectId("5ead6e7857bb72a10bcf0669"), "Name" : "Chris", "SubjectName" : "MongoDB" } { "_id" : ObjectId("5ead6e7857bb72a10bcf066a"), "Name" : "Chris", "SubjectName" : "MongoDB" } { "_id" : ObjectId("5ead6e7857bb72a10bcf066b"), "Name" : "Chris", "SubjectName" : "MongoDB" }