我正在尝试将MongoDB与this unity tutorial一起应用MongoDB购买了mLab,因此通过mongoDB地图集完成mongoDB的登录。而且它们仅支持MongoDB 3.6及更高版本。
我已经使用 AWS 创建了集群(类似于GUI mLab的集群),
mongodb+srv://user_name:<password>@testmp-pkump.mongodb.net/test?retryWrites=true
几件事:
项目名称不是“ test”(如此处所说,就在retryWrites = true之前):mongodb + srv://:@ testmp-pkump.mongodb.net / test?retryWrites = true < / p>
我已将此链接传递给以下代码:private const string MONGO_URI,对于用户名,我写我添加到集群中的用户,对于密码,我写我已经输入的密码添加到集群中的用户。 -不是我用来创建MongoDB帐户的用户
运行“服务器”场景时出现错误:=
ArgumentException: Invalid keyword 'mongodb+srv://:@serverclientmp-
1oqao.gcp.mongodb.net/test?retrywrites'.
MongoDB.Driver.MongoConnectionStringBuilder.set_Item (System.String
keyword, System.Object value)
System.Data.Common.DbConnectionStringBuilder.ParseConnectionStringNonOdbc
(System.String connectionString)
System.Data.Common.DbConnectionStringBuilder.ParseConnectionString
(System.String connectionString)
System.Data.Common.DbConnectionStringBuilder.set_ConnectionString
(System.String value) MongoDB.Driver.MongoConnectionStringBuilder..ctor
(System.String connectionString)
MongoDB.Driver.MongoClient.ParseConnectionString (System.String
connectionString) MongoDB.Driver.MongoClient..ctor (System.String
connectionString) Mongo.Init () (at Assets/Scripts/Database/Mongo.cs:16)
Server.Init () (at Assets/Scripts/Server.cs:40) Server.Start () (at
Assets/Scripts/Server.cs:28)
我尝试将API兼容级别更改为.NET 4.x,并出现以下错误:
ArgumentException: Invalid option 'retryWrites'.
Parameter name: url
MongoDB.Driver.MongoUrlBuilder.Parse (System.String url) (at
<6da29fc855c44d33ad78b3e27475ff27>:0)
MongoDB.Driver.MongoUrlBuilder..ctor (System.String url) (at
<6da29fc855c44d33ad78b3e27475ff27>:0)
MongoDB.Driver.MongoUrl..ctor (System.String url) (at
<6da29fc855c44d33ad78b3e27475ff27>:0)
MongoDB.Driver.MongoClient.ParseConnectionString (System.String
connectionString) (at <6da29fc855c44d33ad78b3e27475ff27>:0)
MongoDB.Driver.MongoClient..ctor (System.String connectionString) (at
<6da29fc855c44d33ad78b3e27475ff27>:0)
Mongo.Init () (at Assets/Script/Database/Mongo.cs:15)
Server.Init () (at Assets/Script/Server.cs:38)
Server.Start () (at Assets/Script/Server.cs:27)
我想知道我需要在脚本中添加些什么才能使其正常工作,或者本教程是否过时而需要采取新的方法。
谢谢
答案 0 :(得分:0)
我知道我已经晚了8个月,但是,我最近开始在Unity中使用MongoDB,我不知道这是否会有所帮助,但简短的答案是我不确定。但是我设法连接到我的远程和本地数据库,因此我将在下面解释如何做到这一点。
详细答案:
我没有观看您跟随的教程视频,但是我设置了与这些dll files的连接(我假设您还为它们创建了 Plugins 文件夹)。至于“教程”,我只是遵循了此快速入门guide和此one的知识。我刚刚阅读了documentation。
最后,当我第一次尝试连接到远程数据库时出现了一个错误,但是也许是因为我的代码被包裹在try catch块中,所以它不会产生您提供的错误,而是这样的:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
typedef struct F
{
char *Titel;
struct F *Next;
struct F *Prev;
} TCD;
void swapString( char **str1, char **str2 )
{
char *temp = *str2;
*str2 = *str1;
*str1 = temp;
}
TCD *partition( TCD *Start, TCD *End, int( *cmp )(const void *, const void*) )
{
TCD *partitionIdx = Start;
TCD *i;
for ( i = Start; i != End; i = i->Next )
{
if ( cmp( i->Titel, End->Titel ) < 0 )
{
swapString( &i->Titel, &partitionIdx->Titel );
//NOTE: I disabled the following line from the original code, as it was doing nonsense. It was causing a node to point to itself.
//partitionIdx->Prev = partitionIdx;
partitionIdx = partitionIdx->Next;
}
}
swapString( &partitionIdx->Titel, &End->Titel );
return partitionIdx;
}
void Quicksort( TCD *Start, TCD *End, int( *cmp )(const void *, const void *) )
{
//NOTE: In the following if condition, I disabled part of the original code, because a partition of two elements must be sorted
if ( Start != NULL && End != Start /*&& End != Start->Next*/ )
{
TCD *partitionIdx = partition( Start, End, cmp );
if ( Start != partitionIdx )
Quicksort( Start, partitionIdx->Prev, cmp );
if ( partitionIdx != End )
Quicksort( partitionIdx->Next, End, cmp );
}
}
// NOTE:
// The following functions are not part of the algorithm, but are only
// used to test the algorithm.
void AddToList( TCD **head, TCD **tail, char *str )
{
TCD *p;
//allocate new node and fill it with the data
p = malloc( sizeof(*p) );
assert( p != NULL );
p->Titel = str;
p->Next = NULL;
p->Prev = *tail;
//attach new node to list by updating head or next pointer
if ( *head == NULL )
*head = p;
else
(*tail)->Next = p;
//update tail pointer too
*tail = p;
}
void PrintList( FILE *stream, TCD *head )
{
TCD *p;
for ( p = head; p != NULL; p = p->Next )
{
fprintf( stream, "%s\n", p->Titel );
}
fprintf( stream, "\n" );
}
void FreeList( TCD *head )
{
TCD *p = head;
while ( p != NULL )
{
TCD *tmp = p;
p = p->Next;
free( tmp );
}
}
int main( void )
{
TCD *head = NULL, *tail = NULL;
//create linked list with a bit of unsorted test data
AddToList( &head, &tail, "string8" );
AddToList( &head, &tail, "string4" );
AddToList( &head, &tail, "string2" );
AddToList( &head, &tail, "string7" );
AddToList( &head, &tail, "string3" );
AddToList( &head, &tail, "string5" );
AddToList( &head, &tail, "string1" );
AddToList( &head, &tail, "string6" );
//print list before sorting
fprintf( stderr, "List before sort:\n" );
PrintList( stderr, head );
//do the actual sorting
Quicksort( head, tail, strcmp );
//print list after sorting
fprintf( stderr, "List after sort:\n" );
PrintList( stderr, head );
//free the linked list
FreeList( head );
return 0;
}
发生这种情况是因为我忘记将尖括号从代码中删除,而使用了它-
这是我连接到Atlas群集的方式:
Unable to authenticate using sasl protocol mechanism SCRAM-SHA-1 mongo c# driver