我的MongoDB的瞬間在服務器,全日空我我的流星的應用程序連接到該數據庫使用代碼:的lib/connection.js插入數據到外部的MongoDB與流星應用
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();
}
});
的connextion到外部蒙戈成立,並在服務器中創建集合測試,但我的應用程序仍連接到本地蒙戈當我插入我的收藏:書:
你代碼:收藏/ 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);
代碼客戶端/ 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
我怎樣才能修改我的代碼,使數據插入外部數據庫 – bastin