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.
Related
We are using sequelize package to connect to mssql server. Our backend code is in javascript.
We have a working code like below:
const sequelize = new Sequelize({
logging:log,
dialect:'mssql',
dialectModulePath: 'msnodesqlv8/lib/sequelize'
dialectOptions:{
connectionString: process.env.connectionString,
encrypt: false
},
operatorAliases: false
})
Below is the format of connectionString we are using in above snippet:
Driver={ODBC Driver 17 for SQL Server}; Server=<<Servername>>;Database=<<Database>>;Trusted_Connection=yes;
And in package.json I can see below 3 packages:
"msnodesqlv8":"^2.4.7",
"sequelize":"^4.41.2",
"sequelize-msnodesqlv8":"^0.2.6-beta.8"
In official doc of sequelize, I can see
const sequelize = new Sequelize('database', 'username', 'password', {
host: 'localhost',
dialect:'mssql',
operatorsAliases: false,
pool: {
max: 5,
min: 0,
acquire: 30000,
idle: 10000
},
// SQLite only
storage: 'path/to/database.sqlite'
});
There is no mention about msnodesqlv8. Right now connection is working fine. But I was just trying to understand if sequelize uses tedious under the hood in order to have appropriate drivers so that connection to DB can be made. Then what is the use of msnodesqlv8?
In msnodesqlv8 official docs I can see it has some enhanced security features.
What I am trying to achieve by understanding this?
I want to remove the dependency of my code from msnodesqlv8 and snippet provided in official document of sequelize for mssql is not working for me.
Reason for removing dependency of msnodesqlv8?
We are migrating code to linux and msnodesqlv8 is compatible with linux which has dependency on msodbcsql17 driver which needs to be installed separately.
After going to the pain of switching to the msnodesqlv8 driver today, I felt like I should comment on this... unfortunately my rep isn't high enough to comment so you get an answer instead :)
You're correct, many people seem to be using the msnodesqlv8 driver for the integrated security aspects.
I does have a dependency on msodbcsql17 (be sure not to try msodbcsql18). And this dependency is a pain to get in place. Word of warning.. trying to use it in a debian based docker image results in segfaults. We switched to alpine based and the segfaults cleared up.
What I haven't seen mentioned anywhere is the significant performance improvement you get from using msnodesqlv8. Small example, we have a simple query (takes .3 seconds to execute and another .3 to return 29000 <1kb rows using the JDBC driver) that would take 58 seconds using tedious. That was using tedious directly (not through sequelize or mssql for node). Almost all of that time was it reading the result stream. Switching to msnodesqlv8 reduced the time to under 2 seconds.
Summary: Pain to install. Much better performance for some workloads.
I'm trying to use the mysql module to connect to my database. But everytime, I get the following error: read eCONNRESET There is problem. (Note, that last part is from my console log. See below.)
I don't think this is a problem with database security settings. I've been trying to connect to my new database (hosted on AWS) for the last several days with no luck. Then, just now I attempted to connect to an Azure database that has been running smoothly for a couple years. Same problem: read eCONNRESET.
By the way, if I randomly change the host string to something invalid, my code returns an error saying the host wasn't found. So that tells me it's working to some extent.
I'm very new to the coding world and need all the help I can get.
Here's my code:
console.log('starting Launch');
var mysql = require('mysql');
var connection = mysql.createConnection({
host : '....windows.net',
user : 'test',
password : 'test',
port : '1433'
})
console.log('step2')
connection.connect(function (err) {
if (!err)
console.log("conncetd");
else
console.log(err + "There is problem");
});
Copy full error message.
Check connectivity to your DB instance, use nmap (linux) or telnet (windows). If you can't reach host - check your local machine and server firewall, restrictions. If you can, go to 2.
Try to use different MySQL client, MySQL WorkBench, HeidiSQL, DBeaver.
If you can't - than something wrong with MySQL configuration. If you can, go to 3.
Copy info about: OS, node version, mysql module version.
you could try
mysql.createPool({});
instead of
mysql.createConnection({})
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 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
I'm trying to use Nodejs to get data from Meteorjs mini mongo database. Here is my code:
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://127.0.0.1:3001/meteor', function(err, db) {
if(err) throw err;
console.log("Connected to Database");
var test = db.collection("apps");
test.insert({"_id":"selfDefinedID"}, function(err,docs){
console.log("docs inserted");
console.log(docs);
});
test.find({"_id":"selfDefinedID"}).toArray(function(err,docs){
console.log("docs founded");
console.log(docs);
});
});
Insert data works fine. But, I can't retrieve data from meteor mini mongo database. And I got an error:
{ [MongoError: Connection Closed By Application] name: 'MongoError' }
Is it possible to retrieve Meteor mini mongo data using Nodejs? If possible, how?
The database meteor uses is a normal mongo database. You can connect to it like any other mongo db. If you are still in development mode, then the database runs at mongodb://localhost:3001/meteor, otherwise, in a bundled app, it's just the db you specified yourself using MONGO_URL.
On a windows machine, I created a new, blank, meteor project, and started it up. I then created a test script, npm installed the mongodb library, and ran your script and it worked fine. First run I get "docs inserted" and "docs founded", on subsequent runs obviously the insert is failing, but the find still works.
So two questions, first is this the same script your getting the error with? And two, if you create a blank meteor project and try it do you get the same error?