私はJObject
を作成するService1を持っています。それから私はService2をmongo DBにそのJObjectを挿入します。MongoDBの子のためのObjectIDを自動的に作成する方法
Service1のは
var doc = GetDocument();
var jDoc = new JObject(
new JProperty("_id", doc.DocumentID),
new JProperty("url", doc.DocumentLink),
new JProperty("cost", null),
new JProperty("context", new JObject(
new JProperty("endTime", null),
new JProperty("startTime", doc.DocumentCreated))),
new JProperty("tasks", new JObject(
new JProperty("phase", "completed"),
new JProperty("initialTask", new JObject(
new JProperty("name",doc.DocumentName),
new JProperty("input", "someinput"))))));
そして
public async Task Create(JObject jDoc)
{
var collection = _mongoDatabase.GetCollection<BsonDocument>("units");
var bDoc = BsonDocument.Parse(jDoc.ToString());
await collection.InsertOneAsync(bDoc);
}
}
Service1のルート文書要素の_id
作成MongoDBの
サービス2に挿入サービス2に、このjオブジェクトを渡すイム。私はService2がmongoDbにドキュメントを挿入するときに、context
、tasks
、initialTask
のような子プロパティのために_id
を自動的に作成しますが、子供向けには_id
を作成しません。
質問
1>どのように私はautomatially、すべての子供のための_id
を作成するのですか?
を自動的に作成できない場合、_id
をService1として作成する場合は、MongoDB.Deriver
を参照せずにService1でObjectIDを作成できます。 Service2のみがMongoDB.Driver
を参照していることに注意してください。 Service1にはMongoDB.Driver
への参照がありません。 私は、パラメータとしてドキュメントオブジェクトを使用せずに、次の形式
"_id" : ObjectId("559b3cc8bf13a6740d7d50b0")
であってもよいです。 – Veeram
JObjectのクラスではなく、 –