Question: I've written a custom comparer that sorts strings and numeric. This all works fine.

However I'm rewriting my whole BLL to use LINQ where possible as I do like the syntax. Now i'm stumbling onto using my custom comparer. As LINQ syntax (query based) will not allow to use custom comparers Im now using method based LINQ.

But in order to make it to work, I need to do an intermediate ToList(), which again works fine, but looks somewhat weird to me? 

```
        var areas = cc.Areas.Where(a => a.ProjectId == ProjectId).ToList()
                            .OrderBy(a => a.UnitNumber, new Common.Comparers.StringNumericComparer());

```

Now i'm unsure if this has to do with the SQL query to be executed first and then the results sorted in my C# code side, but this is beyond my knowledge.
Does ToList() force the first part of the linq query to be executed on the database?

Answer: 
If you look into the source code of jeroenooms/mongolite you can see that it doesn't support authentication yet:

<https://github.com/jeroenooms/mongolite/blob/master/R/mongo.R>

```
mongo_collection_new <- function(uri = "mongodb://localhost", db = "test", collection = "test"){
 stopifnot(is.character(uri))
 stopifnot(is.character(db))
 stopifnot(is.character(collection))
 .Call(R_mongo_collection_new, uri, db, collection)
}

```
It is tried and true that **mongolite** (v0.7 as of today) supports authenticated connection to a *remote* 3.2.x MongoDB (as opposed to *localhost*).

The example below jeroenooms provides himself worked:

```
library(mongolite)
mongo(collection = "mtcars", url = "mongodb://readwrite:test@ds043942.mongolab.com:43942/jeroen_test")

```

To explain:

* `mtcars` is the name of the MongoDB "collection" (or "table" if you insist). It could be a name that does not exist yet.
* `readwrite` is the user name of your mongodb
* `test` is the password of the user "readwrite"
* `ds043942.mongolab.com` is the remote host, which could be replaced by ip address, i.e. 23.20.234.21
* `43942` is the port number. By default in MongoDB, it is 27017
* `jeroen_test` is the name of the database instance in use, which has to exist already

Running the commands above in R will print:

> 
> Mongo Message: SCRAM: authenticating "readwrite" (step 1)
> 
> 
> Mongo Message: SCRAM: authenticating "readwrite" (step 2)
> 
> 
> Mongo Message: SCRAM: authenticating "readwrite" (step 3)
> 
> 
> Mongo Message: SCRAM: "readwrite" authenticated
> 
> 
> ...
> 
> 
> 

---

I tried to replace it with my own remote host info. It didn't work in the beginning, which turned to be the user role issue rather than **mongolite** issue. After ensuring a user with correct readWrite roles, I connected to my remote 3.2.x MongoDB via **mongolite** package.

The following 2 sources were of great help to me in setting up users in MongoDB:

* [enable-authentication](https://docs.mongodb.org/manual/tutorial/enable-authentication/)
* [Manage User and Roles](https://docs.mongodb.org/manual/tutorial/manage-users-and-roles/)