Unable to connect to MongoDB when using a URI with credentials
up vote
1
down vote
favorite
I'm trying to build a simple CRUD API with the MongoDB Rust driver but I'm failing to insert anything into the DB. I'm using Mlab to host my database.
The code that I'm running:
#[macro_use(bson, doc)]
extern crate bson;
extern crate mongodb;
use mongodb::db::ThreadedDatabase;
use mongodb::{Client, ThreadedClient};
fn main() {
let client = Client::with_uri(
"mongodb://<my_db_username>:<my_db_password>@ds235711.mlab.com:35711/rustcrud",
)
.expect("Failed to initialize client");
let coll = client.db("rustcrud").collection("test");
coll.insert_one(doc! { "title": "Back to the Future" }, None)
.unwrap();
}
And the error that I get:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: OperationError("not authorized on rustcrud to execute command { insert: "test", $db: "rustcrud" }")', libcore/result.rs:1009:5
What am I doing wrong?
mongodb rust
add a comment |
up vote
1
down vote
favorite
I'm trying to build a simple CRUD API with the MongoDB Rust driver but I'm failing to insert anything into the DB. I'm using Mlab to host my database.
The code that I'm running:
#[macro_use(bson, doc)]
extern crate bson;
extern crate mongodb;
use mongodb::db::ThreadedDatabase;
use mongodb::{Client, ThreadedClient};
fn main() {
let client = Client::with_uri(
"mongodb://<my_db_username>:<my_db_password>@ds235711.mlab.com:35711/rustcrud",
)
.expect("Failed to initialize client");
let coll = client.db("rustcrud").collection("test");
coll.insert_one(doc! { "title": "Back to the Future" }, None)
.unwrap();
}
And the error that I get:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: OperationError("not authorized on rustcrud to execute command { insert: "test", $db: "rustcrud" }")', libcore/result.rs:1009:5
What am I doing wrong?
mongodb rust
The error message is pretty clear:not authorized on rustcrud to execute command { insert: "test", $db: "rustcrud" }")
— your credentials are bad.
– Shepmaster
Nov 22 at 0:07
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
I'm trying to build a simple CRUD API with the MongoDB Rust driver but I'm failing to insert anything into the DB. I'm using Mlab to host my database.
The code that I'm running:
#[macro_use(bson, doc)]
extern crate bson;
extern crate mongodb;
use mongodb::db::ThreadedDatabase;
use mongodb::{Client, ThreadedClient};
fn main() {
let client = Client::with_uri(
"mongodb://<my_db_username>:<my_db_password>@ds235711.mlab.com:35711/rustcrud",
)
.expect("Failed to initialize client");
let coll = client.db("rustcrud").collection("test");
coll.insert_one(doc! { "title": "Back to the Future" }, None)
.unwrap();
}
And the error that I get:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: OperationError("not authorized on rustcrud to execute command { insert: "test", $db: "rustcrud" }")', libcore/result.rs:1009:5
What am I doing wrong?
mongodb rust
I'm trying to build a simple CRUD API with the MongoDB Rust driver but I'm failing to insert anything into the DB. I'm using Mlab to host my database.
The code that I'm running:
#[macro_use(bson, doc)]
extern crate bson;
extern crate mongodb;
use mongodb::db::ThreadedDatabase;
use mongodb::{Client, ThreadedClient};
fn main() {
let client = Client::with_uri(
"mongodb://<my_db_username>:<my_db_password>@ds235711.mlab.com:35711/rustcrud",
)
.expect("Failed to initialize client");
let coll = client.db("rustcrud").collection("test");
coll.insert_one(doc! { "title": "Back to the Future" }, None)
.unwrap();
}
And the error that I get:
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: OperationError("not authorized on rustcrud to execute command { insert: "test", $db: "rustcrud" }")', libcore/result.rs:1009:5
What am I doing wrong?
mongodb rust
mongodb rust
edited Nov 22 at 0:07
Shepmaster
145k11274408
145k11274408
asked Nov 21 at 23:53
Hugo Sanchez
294
294
The error message is pretty clear:not authorized on rustcrud to execute command { insert: "test", $db: "rustcrud" }")
— your credentials are bad.
– Shepmaster
Nov 22 at 0:07
add a comment |
The error message is pretty clear:not authorized on rustcrud to execute command { insert: "test", $db: "rustcrud" }")
— your credentials are bad.
– Shepmaster
Nov 22 at 0:07
The error message is pretty clear:
not authorized on rustcrud to execute command { insert: "test", $db: "rustcrud" }")
— your credentials are bad.– Shepmaster
Nov 22 at 0:07
The error message is pretty clear:
not authorized on rustcrud to execute command { insert: "test", $db: "rustcrud" }")
— your credentials are bad.– Shepmaster
Nov 22 at 0:07
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
From the project's GitHub repository, issue 256: Add auth to base examples
user-password authentication occurs at the database-level. The user, password, and database are parsed from the URI, but I don't believe we have it set up to automatically authenticate when you create the database object
let client = Client::with_uri("mongodb://x:y@localhost:27017")?;
client.auth("x", "y");
Oh that really is embarrassing. Well it "is" a prototype, and we see why. Worth adding that the same is true for the "database" namespace on the uri as given in the question as this also needs to be omitted. The credentials "should" be stored within theadmin
database, which is where thatauth()
method and all default authentication is actually done. Unless explicitly told otherwise.
– Neil Lunn
Nov 22 at 3:00
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
From the project's GitHub repository, issue 256: Add auth to base examples
user-password authentication occurs at the database-level. The user, password, and database are parsed from the URI, but I don't believe we have it set up to automatically authenticate when you create the database object
let client = Client::with_uri("mongodb://x:y@localhost:27017")?;
client.auth("x", "y");
Oh that really is embarrassing. Well it "is" a prototype, and we see why. Worth adding that the same is true for the "database" namespace on the uri as given in the question as this also needs to be omitted. The credentials "should" be stored within theadmin
database, which is where thatauth()
method and all default authentication is actually done. Unless explicitly told otherwise.
– Neil Lunn
Nov 22 at 3:00
add a comment |
up vote
2
down vote
From the project's GitHub repository, issue 256: Add auth to base examples
user-password authentication occurs at the database-level. The user, password, and database are parsed from the URI, but I don't believe we have it set up to automatically authenticate when you create the database object
let client = Client::with_uri("mongodb://x:y@localhost:27017")?;
client.auth("x", "y");
Oh that really is embarrassing. Well it "is" a prototype, and we see why. Worth adding that the same is true for the "database" namespace on the uri as given in the question as this also needs to be omitted. The credentials "should" be stored within theadmin
database, which is where thatauth()
method and all default authentication is actually done. Unless explicitly told otherwise.
– Neil Lunn
Nov 22 at 3:00
add a comment |
up vote
2
down vote
up vote
2
down vote
From the project's GitHub repository, issue 256: Add auth to base examples
user-password authentication occurs at the database-level. The user, password, and database are parsed from the URI, but I don't believe we have it set up to automatically authenticate when you create the database object
let client = Client::with_uri("mongodb://x:y@localhost:27017")?;
client.auth("x", "y");
From the project's GitHub repository, issue 256: Add auth to base examples
user-password authentication occurs at the database-level. The user, password, and database are parsed from the URI, but I don't believe we have it set up to automatically authenticate when you create the database object
let client = Client::with_uri("mongodb://x:y@localhost:27017")?;
client.auth("x", "y");
answered Nov 22 at 0:12
Shepmaster
145k11274408
145k11274408
Oh that really is embarrassing. Well it "is" a prototype, and we see why. Worth adding that the same is true for the "database" namespace on the uri as given in the question as this also needs to be omitted. The credentials "should" be stored within theadmin
database, which is where thatauth()
method and all default authentication is actually done. Unless explicitly told otherwise.
– Neil Lunn
Nov 22 at 3:00
add a comment |
Oh that really is embarrassing. Well it "is" a prototype, and we see why. Worth adding that the same is true for the "database" namespace on the uri as given in the question as this also needs to be omitted. The credentials "should" be stored within theadmin
database, which is where thatauth()
method and all default authentication is actually done. Unless explicitly told otherwise.
– Neil Lunn
Nov 22 at 3:00
Oh that really is embarrassing. Well it "is" a prototype, and we see why. Worth adding that the same is true for the "database" namespace on the uri as given in the question as this also needs to be omitted. The credentials "should" be stored within the
admin
database, which is where that auth()
method and all default authentication is actually done. Unless explicitly told otherwise.– Neil Lunn
Nov 22 at 3:00
Oh that really is embarrassing. Well it "is" a prototype, and we see why. Worth adding that the same is true for the "database" namespace on the uri as given in the question as this also needs to be omitted. The credentials "should" be stored within the
admin
database, which is where that auth()
method and all default authentication is actually done. Unless explicitly told otherwise.– Neil Lunn
Nov 22 at 3:00
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53422069%2funable-to-connect-to-mongodb-when-using-a-uri-with-credentials%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
The error message is pretty clear:
not authorized on rustcrud to execute command { insert: "test", $db: "rustcrud" }")
— your credentials are bad.– Shepmaster
Nov 22 at 0:07