【发布时间】:2017-05-05 09:45:04
【问题描述】:
我在服务器中有一个 mongodb 的瞬间,我使用该代码将我的流星应用程序连接到该数据库: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:书籍:
你的代码: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);
代码客户端/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
【问题讨论】:
-
如何修改我的代码以使数据插入到外部数据库中
标签: mongodb meteor insert external