How to add an array to a MongoDB document using Java?

前端 未结 4 679
没有蜡笔的小新
没有蜡笔的小新 2020-12-14 09:45

I want to create the following document schema in mongoDB using the java driver

{
  \"_id\": {
    \"$oid\": \"513e9820c5d0d8b93228d7e8\"
  },
  \"suitename\         


        
4条回答
  •  一向
    一向 (楼主)
    2020-12-14 09:53

    You can create an ArrayList which takes in DBObjects.

    List array = new ArrayList();
    

    Add the created DBObject for the object inside the array and add it to the array object created.

    array.add(/* some object */);
    

    Finally, put the array in the main document object.

    document.put("milestones", array);
    

提交回复
热议问题