Unable to connect to MongoDB when using a URI with credentials
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 |
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 '18 at 0:07
add a comment |
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 '18 at 0:07
Shepmaster
154k14306446
154k14306446
asked Nov 21 '18 at 23:53
Hugo SanchezHugo Sanchez
295
295
The error message is pretty clear:not authorized on rustcrud to execute command { insert: "test", $db: "rustcrud" }")
— your credentials are bad.
– Shepmaster
Nov 22 '18 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 '18 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 '18 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 '18 at 0:07
add a comment |
1 Answer
1
active
oldest
votes
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 '18 at 3:00
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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 '18 at 3:00
add a comment |
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 '18 at 3:00
add a comment |
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 '18 at 0:12
ShepmasterShepmaster
154k14306446
154k14306446
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 '18 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 '18 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 '18 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 '18 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.
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 '18 at 0:07