Hi everyone, I'm trying to map a document using the mongodb java driver, for example:
{ "fName" : "abc", "lName" : "456", "dob" : "00", "address" : "xyz" }
from
"nameIdentity" : [ { "fName" : "abc", "lName" : "def", "dob" : "00", "address" : "xyz" }, { "fName" : "123", "lName" : "456", "dob" : "00", "address" : "789" }
If I found a document, then I do nothing to add the document. My problem here is that in my original document there is fname: abc and lname: 456 this corresponds to fname in the first set of nameIdentity and lname in the second set of identifiers. I want this to be one complete coincidence. I tried something like this
List<Document> nameIdentities = (List<Document>) matchedDocument.get("nameIdentity"); for (int i=0;i<nameIdentities.size();i++) { temp.add(nameIdentities.get(0)); quBasicDBObject=new BasicDBObject("$and",temp); } iterable = mongoDatabase.getCollection("entity").find(updatedDocumentTypeOne); if (iterable.first() == null) { updateResult = mongoDatabase.getCollection("entity") .updateOne( new Document("_id", new ObjectId(objectId)), new Document("$push", new Document("nameIdentity", nameList.get(0)))); }
any suggestions I'm wrong in?
source share