必须有一些Meteor 1.3使用开放mongo数据库的例子 本地司机。使用MongoDB Node.JS驱动程序访问集合 另一个本地数据库。新的流星1.3指南声称这是可能的。
答案 0 :(得分:0)
import { mongodb } from 'mongodb';
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect("mongodb://localhost:27017/test",function(err,db) {
var collection = db.collection('test');
var doc1 = {'hello':'doc1'};
var doc2 = {'hello':'doc2'};
var lotsOfDocs = [{'hello':'doc3'}, {'hello':'doc4'}];
collection.insert(doc1);
答案 1 :(得分:0)
这里有一个稍微更新的答案:
import { MongoClient } from 'mongodb';
// Meteor offsets Mongo port by 1, so in case your application is running on 3000
const connection = await MongoClient.connect('mongodb://localhost:3001/', {
useNewUrlParser: true,
useUnifiedTopology: true,
poolSize: 1,
});
const db = await connection.db('testdb');
// then you may create your collection of choice
db.collection('testcollection');
仅供参考,您也可以像这样直接访问 Mongo 驱动程序
import { MongoInternals } from 'meteor/mongo';
MongoInternals.defaultRemoteCollectionDriver()
.mongo.db