美文网首页
MongoDB with Morphia's Details

MongoDB with Morphia's Details

作者: f923bd1a20e9 | 来源:发表于2016-12-06 09:29 被阅读0次

Morphia Grammar


Update arrays of embedded documents


We can use "key.index.key" to locate the values in the array which we intend to modify.

Query query = BallMongoUtils.datastore.createQuery(Ball.class).disableValidation().

field(Mapper.ID_KEY).equal(newObjectId("583646cacd8ba00e54188f73"));

UpdateOperations updateOperations =

BallMongoUtils.datastore.createUpdateOperations(Ball.class)

    .disableValidation()

    .set("newField.0.num","10");

//BallMongoUtils.datastore.createUpdateOperations(Ball.class)

//  .disableValidation()

//  .set("newField."+1+".num","11");

BallMongoUtils.datastore.update(query,updateOperations);

The document below

// colleciton: Ball

{

"_id" : ObjectId("583646cacd8ba00e54188f73"),

"className" : "com.me.entity.Ball",

"name" : "FOUR",

"radius" : 12.45,

"colour" : "6e10f4",

"number" : "10",

"status" : "disable",

"newField" : [

     {

         "num" : "10",

          "name" : "aaa"

     },

     {

          "num" : "11",

          "name" : "bbb"

}

}

}


Update: set a list of embedded documents


First, a List Object was essential .Got it from the Query:

Then set this list into another document:

相关文章

  • MongoDB with Morphia's Details

    Morphia Grammar Update arrays of embedded documents We ca...

  • Morphia快速入门

    使用Morphia 下面的代码说明了如何去初始化一个Morphia的实例。使用这个实例,你可以通过Morphia去...

  • Kubernetes 部署 MongoDB 集群

    一、k8s 部署 MongoDB 1.1 前提准备 MongoDB 镜像 172.18.231.30:5000/s...

  • App privacy details on the App S

    App privacy details on the App Store 在 App Store 上的 App 私...

  • 文章收藏

    How MongoDB's Journaling Works

  • 【mongoDB】MongoDB Shell Script

    MongoDB Shell Script操作备忘https://blog.inhere.top/mongodb-s...

  • Morphia入门

    Morphia官网 开发环境 Jetbrain IDEA Maven 一: maven依赖 官方依赖 二: 入门设...

  • Details

    “我徒弟真的很勤奋啊!” “我徒弟还在睡觉呢!” “哈哈,你徒弟那是随他师傅。” “我是嫁鸡随鸡嫁狗随狗。” “哦...

  • Details

    1.他知道我有段时间喜欢吃烧卖。大冬天,有一天晚自修他去外面补课回来,本来咱俩有点小矛盾,他回来之后把围巾揉成一坨...

  • details

    格式: 概要信息 详细信息 作用:利用summary标签描述简要信息,利用details标签描述详细信息,默...

网友评论

      本文标题:MongoDB with Morphia's Details

      本文链接:https://www.haomeiwen.com/subject/ldolmttx.html