I am following along with the Discover Meteor book and began learning about Collections. I am running Meteor 1.4.
In my app/lib/collections/posts.js I have the following code:
Posts = new Mongo.Collection('posts');
I then proceeded to query Mongo with the following:
meteor:PRIMARY> db.posts.insert({title: "A new post"});
WriteResult({ "nInserted" : 1 })
meteor:PRIMARY> db.posts.find();
{ "_id" : ObjectId("579fd616f0672da283091b1a"), "title" : "A new post" }
As explained, I am supposed to go to my browser console and examine the objects.
Below is a screenshot.
Is this issue related to the content in the book being on an older version of Meteor or am I blatantly missing something?
It appears that these features were once built into Meteor. While running Meteor 1.4 I had to install the Meteor Toys package and can successfully follow along with the instructed commands.
If your autopublish and insecure packages are removed, you should subscribe for certain range of data, so you can use it on client.
In server:
if(Meteor.isServer){
Meteor.publish('Posts',function(){
return Posts.find();
}
}
In Client
Meteor.subscribe('Posts');
It's a good idea to put models in your AppName/models, cuz they should
be loaded parallel in server and client
I hope that would be helpful, Cheers
Related
I'm supporting a legacy Meteor 1.2.1 application using MongoDB Atlas and without any apparent code changes, it is suddenly not showing any documents - The code has not been changed for at least 5 months.
Looking in the DB, the documents are there, but on the server side, the find().fetch() calls are all returning 0 documents:
var documents = Articles.find().fetch();
console.log(`++ Found: ${documents.length} articles`);
logs:
++ Found: 0 articles
Interestingly, if I grab hold of the raw DB connection that Meteor is using and do a query myself, the data is found:
var getDocumentCounts = function (collectionName) {
var Future = Npm.require('fibers/future'), future = new Future();
var db = MongoInternals.defaultRemoteCollectionDriver().mongo.db;
db.collection(collectionName).count(
function(error, results) {
if (error) throw new Meteor.Error(500, "failed");
future.return(results);
}
);
return future.wait();
}
var result = getDocumentCounts('articles');
console.log(`articles: ${result}`);
logs:
articles: 259
The application is using some NPM packages, but is using an npm-shrinkwrap.json (legacy again) to ensure the versions of them are not accidentally upgraded during a restart/rebuild.
Node is from the Jurassic era # v0.10.41
I can't think why the application would suddenly develop this problem. Looking for a simple solution rather than the longwinded "upgrade everything"
Also interestingly, if I connect to my local dev mongo db, everything works fine. The MongDB Atlas is using shards whereas the local mongo is not, but it has had those shards for many many months.
My best opinion is that the problem is being caused by the fact that the mongo driver used by your Meteor version is no longer compatible with the mongo version running in Atlas. Check the Atlas MongoDB version, if possible.
sometimes the console shows these errors on opening the website
GET https://example.com/subpath/_next/static/9ufj5kFJf/_buildManifest.js
[HTTP/3 404 Not Found 311ms]
GET https://example.com/subpath/_next/static/9ufj5kFJf/_ssgManifest.js
[HTTP/3 404 Not Found 334ms]
Loading failed for the <script> with source “https://example.com/subpath/_next/static/9ufj5kFJf/_buildManifest.js”. 1434-247:1:1
Loading failed for the <script> with source “https://example.com/subpath/_next/static/9ufj5kFJf/_ssgManifest.js”.
the app does use ISR and that seems to be working, it does get updated, what do these files do? what could happen if they are missing?
"react": "17.0.2"
"next": "10.1.3",
"node" "15.1.2"
I had the same problem with GCP (Kubernetes engine) with pods count > 1. I resolved the issue by restarting the deployment (all pods).
On that Github issue #Prabir linked to in a comment, someone posted a way to use the generateBuildId function within the Next.js config file:
const execSync = require("child_process").execSync;
const lastCommitCommand = "git rev-parse HEAD";
module.exports = {
async generateBuildId() {
return execSync(lastCommitCommand).toString().trim();
},
};
I work with an app that uses some combination of AWS CodeBuild and Docker images, which prevents direct access to all the git commands so that snippet above didn't work. But using CODEBUILD_BUILD_ID or really any environment variable (unique to either that commit or the build itself) did. I'm not as familiar with the GCP-equivalents but this Cloud Build Docs page makes it seem like $COMMIT_SHA would be a good option to try.
So, I am wondering if there is a way to connect to the mongoDB I have setup in my Cloud9 from an html. I mean, I have already connected to the db from the terminal and everything is working like a charm but I need to do some stuff inside my script in an html document and when I try calling the function which contains this code it does nothing
var MongoClient = require('mongodb').MongoClient
, format = require('util').format;
MongoClient.connect('mongodb://127.0.0.1:27017/ingesoft', function (err, db) {
if (err) {
throw err;
} else {
console.log("successfully connected to the database");
}
db.close();
});
I have saved the same code into a "file.js" and ran it from console using node file.js and it outputs into the console log "successfully connected to the database", plus the terminal which is running mongo's connection shows me one more connection to the db. The thing is, when I try to run that code inside my script it doesn't work. Sorry for my ignorance I am new to mongo.
Any help would be much appreciated
To simplify your question, here's what's going on:
node file.js containing the code in your question is working
pasting the same code to your html file is not
So, getting to the bottom of the issue, let's ask first: what's the difference between running node file.js and putting the code in html?
The difference is that node ... is running on your Cloud9 workspace (let's call it the server machine).
Your MongoDB server is also running on that server machine
The mongodb npm package you installed is also present on the server machine
The url: mongodb://127.0.0.1:27017/ingesoft references 127.0.0.1 which is the localhost for your server
whereas with the code on your browser:
The code is being run on your customer's machine
That machine doesn't have your Mongodb server
Browser's usually don't support require
You can do requires if you bundle code and use something like webpack or browserify. Did you perhaps do that?
If you did indeed package everything, was the mongodb package that you're requiring packaged?
Can the mongodb package be run from the client side?
The url: mongodb://127.0.0.1:27017/ingesoft references 127.0.0.1 which is the localhost for your customer's machine
Basically, as you can see from the above, the two are very different.
If you want to talk to your db, a lot of people go the following route:
Make a server application that implements some form of REST API
That REST API talks to your DB
Your client code knows how to talk to the REST API and get the required data
That way, you only talk to your MongoDB using your server, and the client can talk to your server via the internet.
This is, of course, an oversimplification, but I hope this resolves your confusion.
I am studying the MEAN stack by using this tutorial. But the tutorial connects to a remote mongodb installation. I have MongoDB running in the CentOS7 localhost.
How do I alter the mongoose connect line in server.js from the tutorial link above to connect to a localhost database instead of a remote database?
Here is the current line from server.js that needs to be changed to point to the localhost mongodb:
mongoose.connect('mongodb://node:nodeuser#mongo.onmodulus.net:27017/uwO3mypu');
A specific mongodb database has not been created yet. Do I need to create that also?
I'm fairly new at Mongo to, but I know how to connect to a local db. Basically I had to do the following:
Download the latest version of mongodb from https://www.mongodb.com/download-center?jmp=nav#community (according to your settings)
Once installed, I've created a folder that will be containing my DB.
Use a command line instance to start mongo like this:
mongod --dbpath [YOUR_DB_PATH]
Created a DB use mydb
With that you should have already a mongodb db instance looking for connections on default port. So you can change that line for this:
mongoose.connect('mongodb://localhost:27017/mydb');
Again, this is really basic and it is creating a mongo DB connection with all default options. So this will keep you rolling, but you may need to dig a bit more for custom options.
Hope this helps
I have just started playing around with Meteor and MongoDB for the first time. I come from a .net developer background and MSSQL. I have created a simple web following this tutorial.
Also, I have added the accounts-password package to my app as well. Everything works like a charm, I can add data to my application in real time and I can create users and login, etc, etc. However, when I open up Robomongo and look for the stored data, I do not find any information inside my 'carbrands' collection declared in carbrands.js as
CarBrands= new Meteor.Collection("carbrands");
Also, no users collection is created. My Robomongo profile is connected to localhost. If I try to access CarBrands from Chrome console i get the following output:
> CarBrands.find();
> LocalCollection.Cursor {collection: LocalCollection, selector_id: undefined, selector_f: function, sort_f: null, skip: undefined…}
Where is the meteor data being saved to and how can i view it ?
UPDATE**: I have run mongo command in linux terminal and the result returned are local and test. test is empty. Accessing local returns the same collections as viewed in Robomongo
You need to run:
meteor mongo
from your project, not your usual mongoDB install:
http://docs.meteor.com/#meteormongo
Meteor stores local mongo datasets in APPDIR/.meteor/local/db.
A ps will verify DB location.
ps -ax | grep mongo
1482 ? Sl 170:02 /usr/bin/mongod --config /etc/mongodb.conf
2176 ? Sl 174:46 /home/ell/.meteor/packages/meteor-tool/.1.4.2_3.qrhx4m++os.linux.x86_64+web.browser+web.cordova/mt-os.linux.x86_64/dev_bundle/mongodb/bin/mongod --bind_ip 127.0.0.1 --port 3001 --dbpath /apps/assessment/current/.meteor/local/db --oplogSize 8 --replSet meteor --nojournal