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

前端 未结 4 680
没有蜡笔的小新
没有蜡笔的小新 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:50

    Better use:

    MongoClient client = new MongoClient("localhost",27017);
    
    MongoCollection collection =        client.getDatabase("db").getCollection("collection");
    
    List docs=new ArrayList<>();
    docs.add();
    
    collection.insertMany(docs);
    
    client.close();
    

提交回复
热议问题