gpt4 book ai didi

mongodb - Meteor:列出服务器上的所有集合

转载 作者:可可西里 更新时间:2023-11-01 09:24:23 27 4
gpt4 key购买 nike

我无法列出在服务器上的 Meteor 应用程序中创建的所有集合。

集合位于... /root/packages/lib/collectionName.js

对 collectionName 的操作成功。但是,由于我有很多集合,因此我需要一个函数来检索创建的所有集合的名称。

在服务器函数中加载集合后,一个方法执行以下函数;

MyCollection = Mongo.Collection.getAll();
console.log(MyCollection);


[ { name: 'users',
instance:
{ _makeNewID: [Function],
_transform: null,
_connection: [Object],
_collection: [Object],
_name: 'users',
_driver: [Object],
_restricted: true,
_insecure: undefined,
_validators: [Object],
_prefix: '/users/' },
options: undefined },
{ name: 'MeteorToys/Impersonate',
instance:
{ _makeNewID: [Function],
....

Meteor 创建的用户集合就在那里。但是创建的所有集合,其中 3 个带有 Collection2 包的集合都没有显示。

我错过了什么?

如果我需要 child_process 库并执行一系列命令..“meteor mongo”...“db.getCollectionNames()”,这意味着什么?

最佳答案

要列出服务器上的所有集合,请使用 RemoteCollectionDriver 访问预先存在的 MongoDB 集合。要实现此服务器端,您可以遵循以下异步模式:

var shell = function () {
var Future = Npm.require('fibers/future'),
future = new Future(),
db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;

db.collectionNames(
function(error, results) {
if (error) throw new Meteor.Error(500, "failed");
future.return(results);
}
);
return future.wait();
};

关于mongodb - Meteor:列出服务器上的所有集合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33826774/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com