我在服务器上有一个mongodb瞬间,我使用该代码将我的meteor应用程序连接到此数据库: lib / connection.js
MONGO_URL = 'mongodb://xxxxxxxx';
var mongoClient = require("mongodb").MongoClient;
mongoClient.connect(MONGO_URL, function (err, db) {
if (err) {
console.log('Unable to connect to the mongoDB server. Error:', err);
} else {
console.log('Connection established to cc', MONGO_URL);
var collection = db.collection('test');
var test1= {'hello':'test1'};
collection.insert(test1);
db.close();
}
});
建立了对外部mongo的连接,并在服务器中创建了集合测试,但是当我插入我的集合时,我的应用程序仍然连接到本地mongo:books:
thee code:collections / Books.js
Books= new Mongo.Collection('books');
BooksSchema= new SimpleSchema({
name: {
type: String,
label: "Name"
autoform:{
label: false,
placeholder: "schemaLabel"
}
},
categorie:{
type: String,
label: "Categorie"
autoform:{
label: false,
placeholder: "schemaLabel"
}
},
});
Meteor.methods({
deleteBook: function(id) {
Cultures.remove(id);
}
});
Books.attachSchema(BooksSchema);
code client / books.html
<template name="books">
<p>add new books </p>
{{> quickForm collection="Books" id="newBook" type="insert" class="nform" buttonContent='ajouter' buttonClasses='btn bg-orange'}}
</template>
帮助bleaaaaaz
答案 0 :(得分:0)
您应该指定应该在MONGO_URL
环境变量中使用的数据库,而不是在您的代码中。如果您在本地工作,请按以下方式启动您的应用程序:
MONGO_URL="mongodb://xxxxxxxx" meteor
<强> UPD 强>
不了解Windows。请参阅此SO question。
看起来你应该在windows中设置env vars:
set MONGO_URL=mongodb://localhost:27017/mydbname
答案 1 :(得分:0)
好吧,你知道Ramil,我在Windows上创建一个新的系统环境变量,MOGO_URL的值等于:mongodb:// xxxxxxxx,它可以工作;应用程序连接到服务器中的数据库,并将数据插入其中。 现在我的问题是如何从该数据库获取数据,我用户Microsoft azure用API DocumentDB存储数据库