MongoDB怎么用C#插入Bson复杂对象,如数组,布尔值等

4 篇文章 0 订阅
2 篇文章 0 订阅

话不多说直接上BsonDocument代码,至于怎么插入,不想解释,只举例两种类型,其它的自己类推:
var document = new BsonDocument
{
{“id”, pd.id },
{“name”,pd.name},
{“acct”,pd.acct},
{“pass”,pd.pass},
{“lv”,pd.lv },
{“imgHeadUrl”,pd.imgHeadUrl },
{“liceneVal”,pd.liceneVal },
{“curExp”,pd.curExp },
{“needExp”,pd.needExp },
{“state”,(int)pd.state },
{“coin”,pd.coin },
{“diamond”,pd.diamond },
{“salutation”,pd.salutation },
{“time”,curTime },
{“achievementPoints”,pd.achievementPoints },

            {"taskProgress",new BsonArray
            {
                new BsonDocument
                {
                    { "id",pd.taskProgress[0].id},
                    {"name",pd.taskProgress[0].name },
                    {"task",pd.taskProgress[0].task },
                    {"progress",pd.taskProgress[0].progress },
                    {"taked",pd.taskProgress[0].taked }
                 },
                new BsonDocument
                {
                    { "id",pd.taskProgress[1].id},
                    {"name",pd.taskProgress[1].name },
                    {"task",pd.taskProgress[1].task },
                    {"progress",pd.taskProgress[1].progress },
                    {"taked",pd.taskProgress[1].taked }
                },
            } },

            {"carInfos",new BsonArray
            {
                new BsonDocument
                {
                    {"id",pd.carInfos[0].id },
                    {"name",pd.carInfos[0].name },
                    {"des",pd.carInfos[0].Des },
                    {"color",pd.carInfos[0].color },
                    {"skin",pd.carInfos[0].skin },
                    {"costType",pd.carInfos[0].costType },
                    {"costVal",pd.carInfos[0].costType }
                }
            } },

            {"friendInfos",new  BsonArray{
                {
                 new BsonDocument
                {
                    {"id",pd.friendInfos[0].id },
                    {"name",pd.friendInfos[0].name },
                    {"state",pd.friendInfos[0].state },
                    {"chatInfos",new BsonArray
                    {
                        new BsonDocument
                        {
                             {"type",pd.friendInfos[0].chatInfos[0].type },
                             {"name",pd.friendInfos[0].chatInfos[0].name},
                             {"chat",pd.friendInfos[0].chatInfos[0].chat },
                             {"time",pd.friendInfos[0].chatInfos[0].time }
                        }

                    }},
                }},
            } },

            {"backPackInfos",new BsonArray
            {
                new BsonDocument
                {
                    {"id",pd.backPackInfos[0].id },
                    {"amount",pd.backPackInfos[0].amount },
                    {"expirationTime",pd.backPackInfos[0].expirationTime },
                    {"receiveTime",pd.backPackInfos[0].reciveTime }
                }
            }},

            {"chatInfos",new BsonArray
            {
                new BsonDocument
                {
                    {"type",pd.chatInfos[0].type },
                    {"name",pd.carInfos[0].name },
                    {"chat",pd.chatInfos[0].chat },
                    {"time",pd.chatInfos[0].time }
                },
            } },

            {"settingConfig",
                new BsonDocument
                {
                    {"quality",pd.settingConfig.quality },
                    {"sound",pd.settingConfig.sound },
                    {"controlType",pd.settingConfig.controlType },
                    {"isVibrate",pd.settingConfig.isVibrate },
                    {"sensitity",pd.settingConfig.sensitity }
                } 
             },

            {"isSignArr",new BsonArray
            {
                new BsonBoolean(false)
            } }
        };
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值