How do I do the following in MongoDB Driver?
如何在MongoDB驱动程序中执行以下操作?
Update MyTable1
set MyTable1.ColumnA = MyTable2.ColumnZ
from MyTable1
inner join MyTable2
on MyTable2.PrimaryKeyValue = MyTable1.ForeignKeyValue
Where MyTable1.ColumnA is null;
For example, a MongoDb Driver select equivalent query would look like this:
例如,MongoDB驱动程序SELECT EQUEMENT查询将如下所示:
IMongoClient client = new MongoClient("mongodb://host:port/");
IMongoDatabase database = client.GetDatabase("InventoryPOS");
IMongoCollection<BsonDocument> collection = database.GetCollection<BsonDocument>("Collection1");
// Created with Studio 3T, the IDE for MongoDB - https://studio3t.com/
var options = new AggregateOptions() {
AllowDiskUse = true
};
PipelineDefinition<BsonDocument, BsonDocument> pipeline = new BsonDocument[]
{
new BsonDocument("$project", new BsonDocument()
.Add("_id", 0)
.Add("Collection1", "$$ROOT")),
new BsonDocument("$lookup", new BsonDocument()
.Add("localField", "Collection1.ForeignKeyId_Property")
.Add("from", "Collection2")
.Add("foreignField", "PrimaryKeyId_Property")
.Add("as", "Collection2")),
new BsonDocument("$unwind", new BsonDocument()
.Add("path", "$Collection2")
.Add("preserveNullAndEmptyArrays", new BsonBoolean(false))),
new BsonDocument("$project", new BsonDocument()
.Add("Collection1.PropertyA", "$Collection1.PropertyA")
.Add("Collection2.PropertyZ", "$Collection2.PropertyZ")
.Add("_id", 0))
};
I'm looking for a way to run an update using MongoDb Driver, c# where I can use a query like I have above to set "Collection1.PropertyA" to the value of "Collection2.PropertyZ"
我正在寻找一种使用MongoDB驱动程序c#运行更新的方法,其中我可以使用上面的查询将“Collection1.PropertyA”设置为“Collection2.PropertyZ”的值。
Does that help explain what I'm asking for help with?
这能解释我请求帮助的原因吗?
更多回答
Do you want to use update operaion in C# with MongoDB driver?
你想在C#中使用MongoDB驱动程序的更新操作吗?
Mongo has no sql, has no tables, has no join.
Mongo没有SQL,没有表,没有连接。
I've updated my question to hopefully better explain what I'm after.
我已经更新了我的问题,希望能更好地解释我想要什么。
我是一名优秀的程序员,十分优秀!