Mongodb avoid duplicate entries

后端 未结 6 705
情歌与酒
情歌与酒 2020-12-08 14:34

I am newbie to mongodb. May I know how to avoid duplicate entries. In relational tables, we use primary key to avoid it. May I know how to specify it in Mongodb using java?<

6条回答
  •  甜味超标
    2020-12-08 15:12

    Theon solution didn't work for me, but this one did:

    BasicDBObject query = new BasicDBObject(, 1);
    collection.ensureIndex(query, , true);
    

提交回复
热议问题