Question

Is it possible to access a MongoDB Database Server from a Windows Phone 8 App?

Is it possible to do so using Native App, using c# as the programming language?

Please excuse me if this is a stupid question. I am new to MongoDB.

I wish to perform CRUD operations from the Phone.

The official C# Driver targets .Net Framework v3.5 I failed to install it on the Windows phone project using nugget.

error-

Install failed. Rolling back...
Install-Package : Could not install package 'mongocsharpdriver 1.8.3'. You are trying to install this package into a project that targets 
'WindowsPhone,Version=v8.0', but the package does not contain any assembly references or content files that are compatible with that 
framework. For more information, contact the package author.
At line:1 char:1
+ Install-Package mongocsharpdriver
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Install-Package], InvalidOperationException
    + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PowerShell.Commands.InstallPackageCommand
Was it helpful?

Solution

The drivers won't work for many reasons.

The biggest is that the current .NET drivers/source require synchronous communication support. The Windows Phone .NET libraries only support asynchronous communication. So, anything that's synchronous would need to be changed.

There's a line of code for example in the current code:

tcpClient.Connect(ipEndPoint);

Minimally, this would need to be changed to be in an async method using the await keyword:

await tcpClient.ConnectAsync(ipEndPoint);

However, it's not as simple as that, as the ConnectAsync doesn't support use of the async keyword as it doesn't use Tasks. Instead, it has a different connection syntax where the method expects an object, that has an event which is called when the connection has established. And, that's just one example.

I'd suggest that instead of directly connecting to a MongoDB, you instead use a web server or service to proxy the database communication. There, you could use a REST API for example and use the C# drivers from an ASP.NET hosted application (for example, using the ASP.NET Web APIs).

OTHER TIPS

I suggest you using Sleepy Mongoose which is a full HTTP interface for MongoDB. And accordingly, you don't need any drivers, you just need to perform some HTTP requests to apply CRUD operations from your mobile app.

This npm module - express-restify-mongoose is a good option for people using a node.js server. This library provides mongoose database models with a REST interface.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top