第一步:在Assets中新建Plugins文件夹。
第二步:通过DOS安装Mongodb.Driver,dotnet add package MongoDB.Driver --version 2.7.0
第三步:找这几个动态链接库。将其放到Plugins文件夹中,给大家一个链接,里面有动态链接库你链接:https://pan.baidu.com/s/1iWKFgIL7lApcJ-IvOK129g
提取码:yrdd
第四步:写脚本,挂在游戏对象上即可。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MongoDB.Bson;
using MongoDB.Driver;
public class MongodbTest : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
InsertData();
}
private IMongoCollection<BsonDocument> DatabaseConn()
{
var client = new MongoClient("mongodb://localhost");
var database = client.GetDatabase("test"); //数据库名称
var collection = database.GetCollection<BsonDocument>("WAWA");//连接的表名
return collection;
}
public void InsertData()
{
var document = new BsonDocument{
{"aa",11},
{"bb",22},
{"cc",new BsonDocument{
{"x",33},
{"y",44}
}}
};
var collection = DatabaseConn();
collection.InsertOne(document);
}
}
来源:CSDN
作者:lollapo
链接:https://blog.csdn.net/tie_de_de/article/details/104415930