Problem with external mongo DB connect with meteor app


i m newer wit meteor … i need to connect my existng mongo data base with meteor app

this is my DB (extenal )

> show dbs
items     0.000GB
local     0.000GB
nodeauth  0.000GB
nodeblog  0.000GB
> use items
switched to db items
> show collections

> db.items.find().pretty()
	"_id" : ObjectId("57e2d776282dce039fb6d3e2"),
	"title" : "this is title 00",
	"cteateAt" : ISODate("2016-09-21T18:54:46.294Z")

i added example value

i run this on terminal to connect DB inside meteor application

channasmcs@channasmcs-Inspiron-N5110:~/Documents/Meteorss/hello_01$ MONGO_URL="mongodb://localhost:27017/items"
channasmcs@channasmcs-Inspiron-N5110:~/Documents/Meteorss/hello_01$ meteor
[[[[[ ~/Documents/Meteorss/hello_01 ]]]]]     

=> Started proxy.                             
=> Started MongoDB.                           
=> Started your app.                          

=> App running at: http://localhost:3000/

this is my DB connect meteor code

import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';

import './main.html';
//$export MONGO_URL="mongodb://localhost:27017/items";
Items =  new Mongo.Collection('items');
  items: function(){
  //  Items.insert({title:"this is title 04",cteateAt:new Date()});
  return Items.find();

this is my HTML OUTPUL


    {{#each items}}    
      {{> main}}

<template name="main">
  <li>  {{title}}</li>

when i compile this is out put is empty
this is my console log staus
( in console.log()

M…o.Collection {_transform: null, _connection: Connection, _collection: LocalCollection, _name: "items", _driver: LocalCollectionDriver…}_collection: LocalCollection_connection: Connection_driver: LocalCollectionDriver_insecure: undefined_makeNewID: ()_name: "items"_prefix: "/items/"_restricted: false_transform: null_validators: Object__proto__: Object

i think my DB conenct is wrong :cry: howe solve this ??


Try this

MONGO_URL=mongodb://localhost:27017/items meteor


i tried also but same happend


did you publish/subscribe it ?. Meteor version 1.3+ removed autopublish package so you need to pub/sub in order to work.


Please note that when you do console.log you need to add .fetch() to your query, otherwise you will log the cursor object instead of actual data, which is not very helpful. So to debug you can try:

  items: function(){
  return Items.find();

Also, I don’t see any publication and subscription code in your example. If you don’t have autopublish package added to your project you won’t get any data on the client unless you publish it on the server and then subscribe to it on the client.

Finally, you MUST run meteor like this (you can also use export clause if you want):

MONGO_URL="mongodb://localhost:27017/items" meteor

In your example you’ve set a variable before and meteor didn’t catch this, because in your output you can see that it started its own MongoDB instance:

=> Started MongoDB

That doesn’t happen when you use external db.