Insert Array inside an object in MongoDB

后端 未结 3 694
悲哀的现实
悲哀的现实 2021-02-05 12:11

I am new at MongoDB and I want to insert to mongodb data like this but I couldn\'t figure out how

{
  image = \"cab\"
  tags = [
            [ \"NNP\", 0 ],
             


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-05 13:10

    Did you mean like this?

        BasicDBObject obj = new BasicDBObject();
        obj.put("image", ....);
        for(Tag tag:tags){
            BasicDBObject tagsObj = new BasicDBObject();
            tagsObj.put("NNP",tag.getNNP());
            tagsObj.put("NN",tag.getNN());
            obj.put("tags",tagsObj);
        }
    

提交回复
热议问题