MongoDB与Xamarin.Forms连接数据库问题c#

时间:2017-05-29 18:41:31

标签: c# mongodb mono xamarin.forms

我有以下内容:

MongoClientSettings settings = new MongoClientSettings();
settings.Server = new MongoServerAddress("localhost", 27017);
var client = new MongoClient(settings);

在最后一行我得到了这个:

{System.EntryPointNotFoundException: mono_get_runtime_build_info
  at (wrapper managed-to-native)** System.Runtime.InteropServices.RuntimeInformation:mono_get_runtime_build_info ()
  at System.Runtime.InteropServices.RuntimeInformation.get_FrameworkDescription () [0x00000] in <faa8163a322d41a99fc85eb6d1c29040>:0 
  at MongoDB.Driver.Core.Connections.ClientDocumentHelper.GetPlatformString () [0x00000] in <077b2160c936411eb67f8073bdcbbe94>:0 
  at System.Lazy`1[T].CreateValue () [0x00081] in <d18287e1d683419a8ec3216fd78947b9>:0 
  at System.Lazy`1[T].LazyInitValue () [0x00080] in <d18287e1d683419a8ec3216fd78947b9>:0 
  at System.Lazy`1[T].get_Value () [0x0003a] in <d18287e1d683419a8ec3216fd78947b9>:0 
  at MongoDB.Driver.Core.Connections.ClientDocumentHelper.CreateClientDocument (System.String applicationName) [0x00015] in <077b2160c936411eb67f8073bdcbbe94>:0 
  at MongoDB.Driver.Core.Connections.ConnectionInitializer..ctor (System.String applicationName) [0x00006] in <077b2160c936411eb67f8073bdcbbe94>:0 
  at MongoDB.Driver.Core.Connections.BinaryConnectionFactory..ctor (MongoDB.Driver.Core.Configuration.ConnectionSettings settings, MongoDB.Driver.Core.Connections.IStreamFactory streamFactory, MongoDB.Driver.Core.Events.IEventSubscriber eventSubscriber) [0x00040] in <077b2160c936411eb67f8073bdcbbe94>:0 
  at MongoDB.Driver.Core.Configuration.ClusterBuilder.BuildCluster () [0x0002e] in <077b2160c936411eb67f8073bdcbbe94>:0 
  at MongoDB.Driver.ClusterRegistry.CreateCluster (MongoDB.Driver.ClusterKey clusterKey) [0x000ad] in <42bdb488f5094fc1bb90030259d358c6>:0 
  at MongoDB.Driver.ClusterRegistry.GetOrCreateCluster (MongoDB.Driver.ClusterKey clusterKey) [0x00021] in <42bdb488f5094fc1bb90030259d358c6>:0 
  at MongoDB.Driver.MongoClient..ctor (MongoDB.Driver.MongoClientSettings settings) [0x0002d] in <42bdb488f5094fc1bb90030259d358c6>:0 
  at .....ctor () [0x00025] in ...

我尝试过连线:

var client = new MongoClient(settings);

没有设置,有和没有连接字符串但没有...我能够使用命令提示符和db.movi​​e.insert将文档添加到数据库中,如此处所述 https://www.tutorialspoint.com/mongodb/mongodb_create_database.htm但是当我尝试使用C#驱动程序进行连接时,就像服务器没有运行一样。

请帮忙!并谢谢

1 个答案:

答案 0 :(得分:0)

尝试使用机器的ip,它是你的mongo db的主机。但我建议您开发一些服务器端代码,例如使用节点js。然后将基于休息的请求发送到您的节点js app,并在节点js中,从/向db读取和写入。这比你想要在这里完成的要好得多。您的方法会使您的数据面临风险。