I have the following class structure:
public class DBTestItem
{
public int p0;
public int p1;
public int p2;
public int p3;
public int p4;
public int p5;
public int p6;
public int p7;
public string data;
}
public sealed class MongoTestItem : DBTestItem
{
public ObjectId _id;
}
_id is meaningless to me. p0 - p7 represent a composite key, and data represents the value.
I want to save MongoTestItem
documents where data is unique, and ideally without performing updates as they would be meaningless. In other words, save if data's value does not exist in the collection.
I have looked at the documentation, but can't quite find how to write the statement to meet the above.
I did create a different structure where p0 - p7 makes a composite _id and data is a List, in which case the statement is as follows:
var query = Query<MdbData>.EQ(x => x._id, doc._id);
var update = Update<MdbData>.Push(x => x.data, "somenewvalue");
col.Update(query, update, UpdateFlags.Upsert);
This has different semantics, so the upsert is OK.
I want to write the above so I can evaluate the performance difference.