Tag: 数据库中的

NodeJS / Mongo:通过各种集合循环查询

我正在寻找通过使用NodeJS驱动程序的 MongoDB通过各种集合循环查询。 对于这个testing,我使用'findOne'文档中的示例代码在各种Collections中插入一堆文档: collection.insertMany([{a:1, b:1}, {a:2, b:2}, {a:3, b:3}], {w:1}, function(err, result) { test.equal(null, err); 同时创build各种集合(每个集合至less有一个先前插入的文档实例): testing TEST1 TEST2 TEST3 TEST4 TEST6 test10 我想要的是收集我在数据库中的集合列表(在我的情况下是'test' ): var MongoClient = require("mongodb").MongoClient, test = require("assert"); MongoClient.connect("mongodb://localhost:27017/test", function(err, db) { db.listCollections().toArray(function(err, items) { test.ok(items.length >= 1); console.log(items); db.close(); }); }); 然后popup前面提到的collections列表。 到目前为止,一切都是正确的! 我甚至可以遍历数组来获取集合的名称: var MongoClient = require("mongodb").MongoClient, test = […]