My teammate and developper is in hospital for a while. I am trying to do what I can by so far to carry on our project… Here's my issue. I would like to insert data in a collection if : for each distinct value of field "A", the value "X" of a field "B" doesn't exist. The problem is that others values ("Y","Z") can exist on the same field "B" regarding the structure of the database. Other problem, the database has more than 600millions of object_id so not sure a $lookup works...

{ 
    "_id" : ObjectId("5ca7422ed842e23f5ce8f760"), 
    "vehicle_id" : NumberInt(75), 
    "data_value" : "A", 
    "schema_id" : NumberInt(101), 
    "option_id" : NumberInt(0), 
    "record_id" : NumberInt(0), 
    "location" : "-", 
    "condition" : "-"
}

{ 
    "_id" : ObjectId("5ca7422ed842e23f5ce8f765"), 
    "vehicle_id" : NumberInt(75), 
    "data_value" : "A", 
    "schema_id" : NumberInt(102), 
    "option_id" : NumberInt(0), 
    "record_id" : NumberInt(0), 
    "location" : "-", 
    "condition" : "-"
}

{ 
    "_id" : ObjectId("5ca7422ed842e23f5ce8f766"), 
    "vehicle_id" : NumberInt(101), 
    "data_value" : "A", 
    "schema_id" : NumberInt(101), 
    "option_id" : NumberInt(0), 
    "record_id" : NumberInt(0), 
    "location" : "-", 
    "condition" : "-"
}

{ 
    "_id" : ObjectId("5ca7422ed842e23f5ce8f768"), 
    "vehicle_id" : NumberInt(102), 
    "data_value" : "A", 
    "schema_id" : NumberInt(101), 
    "option_id" : NumberInt(0), 
    "record_id" : NumberInt(0), 
    "location" : "-", 
    "condition" : "-"
}

{ 
    "_id" : ObjectId("5ca7422ed842e23f5ce8f76a"), 
    "vehicle_id" : NumberInt(102), 
    "data_value" : null, 
    "schema_id" : NumberInt(102), 
    "option_id" : NumberInt(0), 
    "record_id" : NumberInt(0), 
    "location" : "-", 
    "condition" : "-"
}

What I would like to do for each "vehicle_id" if the value of a schema_id doesn't exists to insert an object with "new_id","vehicle_id:(concerned)","schema_id:(which doesn't exists)","location:-","data-value:-","option-id:0","record_id:0",condition:"-". In my basic db example it would be to insert "vehicle_id:101","schema_id:102","option_id:0",etc,... Thanks in advance guys

0 Answers