Closed CriztianiX closed 7 years ago
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)?
You can test using this db
mongodb://
dbuser = my_test_user dbpass = qwe123 collection = my_test_collection
These settings works fine with:
mongo ds119014.mlab.com:19014/my_test_db -u
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.
However, it's indeed working with command-line client. I'll need some time to debug it.
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();
});
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
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' }
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 .
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...
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