isage / lua-resty-moongoo

MongoDB library for OpenResty
Do What The F*ck You Want To Public License
118 stars 33 forks source link

Cant connecto to servers in mlab #11

Closed CriztianiX closed 7 years ago

CriztianiX commented 7 years ago

Trying to connect mongod version: 3.4.7 in mlab cloud. In insert i get: collection.lua:100: bad argument #1 to 'gsub' (string expected, got nil)

self._db._moongoo:connect() returns: nil , Can't connect to any of servers

I'm using master branch. So: https://github.com/isage/lua-resty-moongoo/issues/8 seems not work

isage commented 7 years ago

8 is unrelated (it works)

There's either some error in your connection string, or something else. Can you provide more details? What mg:connect() returns (mg being an instance of moongoo)?

CriztianiX commented 7 years ago

You can test using this db

mongodb://:@ds119014.mlab.com:19014/my_test_db

dbuser = my_test_user dbpass = qwe123 collection = my_test_collection

These settings works fine with: mongo ds119014.mlab.com:19014/my_test_db -u -p

isage commented 7 years ago

well,

local mg = require("resty.moongoo")

local mongo, err = mg.new("mongodb://my_test_user:qwe123@ds119014.mlab.com:19014/")

local r, err = mongo:connect()

print(err)

gives me Authentication failed.

isage commented 7 years ago

However, it's indeed working with command-line client. I'll need some time to debug it.

CriztianiX commented 7 years ago

In NodeJS working too...

$ nodejs index.js 
Connected successfully to server
var MongoClient = require('mongodb').MongoClient
  , assert = require('assert');

// Connection URL
var url = 'mongodb://my_test_user:qwe123@ds119014.mlab.com:19014/my_test_db';

// Use connect method to connect to the server
MongoClient.connect(url, function(err, db) {
  assert.equal(null, err);
  console.log("Connected successfully to server");

  db.close();
});
isage commented 7 years ago

Oh, i forgot to add database to connection string. So, i've inserted some data in this collection through cli (db.my_test_collection.insert({test: "test"})) And this code

local mg = require("resty.moongoo")
local printr = require("resty.moongoo.utils").print_r

local mongo, err = mg.new("mongodb://my_test_user:qwe123@ds119014.mlab.com:19014/my_test_db")

local col,err = mongo:db("my_test_db"):collection("my_test_collection"):find_one({})
printr(col)

works as expected:

$ luajit ./test.lua 
[_id] = 59a86afbee37059c113159f9
[test] = test
CriztianiX commented 7 years ago

Not for me...

local mg = require("resty.moongoo")
local printr = require("resty.moongoo.utils").print_r
local mongo, err = mg.new("mongodb://my_test_user:qwe123@ds119014.mlab.com:19014/my_test_db")
local col,err = mongo:db("my_test_db"):collection("my_test_collection"):find_one({})
printr(col)
printr(err)
nil
Can't connect to any of servers,

and insert:

local mg = require("resty.moongoo")
local printr = require("resty.moongoo.utils").print_r
local mongo, err = mg.new("mongodb://my_test_user:qwe123@ds119014.mlab.com:19014/my_test_db")
local col,err = mongo:db("my_test_db"):collection("my_test_collection"):insert({key = "val"})

/usr/local/openresty/lualib/resty/moongoo/collection.lua:100: bad argument #1 to 'gsub' (string expected, got nil)

But, in nodejs is working...

var MongoClient = require('mongodb').MongoClient
  , assert = require('assert');

// Connection URL
var url = 'mongodb://my_test_user:qwe123@ds119014.mlab.com:19014/my_test_db';

// Use connect method to connect to the server
MongoClient.connect(url, function(err, db) {
  assert.equal(null, err);
  console.log("Connected successfully to server");

  db.collection("my_test_collection").findOne({}, function(err, result) {
    if (err) throw err;
    console.log(result);
    db.close();
  });
});
$ node index.js 
Connected successfully to server
{ _id: 59a86afbee37059c113159f9, test: 'test' }
isage commented 7 years ago

Well, that's strange. And this is on the same machine, where cli's working?

On Sep 1, 2017 3:42 PM, "Cristian Haunsen" notifications@github.com wrote:

Not for me...

local mg = require("resty.moongoo")local printr = require("resty.moongoo.utils").print_rlocal mongo, err = mg.new("mongodb://my_test_user:qwe123@ds119014.mlab.com:19014/my_test_db")local col,err = mongo:db("my_test_db"):collection("my_test_collection"):find_one({})printr(col)printr(err)nilCan't connect to any of servers,

and insert:

local mg = require("resty.moongoo")local printr = require("resty.moongoo.utils").print_rlocal mongo, err = mg.new("mongodb://my_test_user:qwe123@ds119014.mlab.com:19014/my_test_db")local col,err = mongo:db("my_test_db"):collection("my_test_collection"):insert({key = "val"}) /usr/local/openresty/lualib/resty/moongoo/collection.lua:100: bad argument #1 to 'gsub' (string expected, got nil)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/isage/lua-resty-moongoo/issues/11#issuecomment-326570180, or mute the thread https://github.com/notifications/unsubscribe-auth/AAQtIT6CKdt67y3rYZYZEE-7VY4vzqvvks5sd_uqgaJpZM4PIIQT .

CriztianiX commented 7 years ago

Ooooo.... i'm so st#pid!

resolve(): Can't connect to any of servers.

In my nginx.conf i've added

resolver 8.8.8.8

Now, working...