更新MongoDB的文档在VB.NET与C#驱动程序 [英] Update MongoDB Document in VB.NET with the C# Driver

查看:258
本文介绍了更新MongoDB的文档在VB.NET与C#驱动程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有更新使用VB.NET和放大器MongoDB中的文件的问题; C#的驱动程序。

我有code返回我想要更新的文档,但我不知道的语法继续

 进口MongoDB.Bson
进口MongoDB.Driver
进口MongoDB.Driver.Builders

昏暗的蒙戈作为MongoServer = MongoServer.Create()
mongo.Connect()
昏暗DB = mongo.GetDatabase(数据库)
昏暗的股票= db.GetCollection(中BsonDocument)(股票)

昏暗getDocument =新QueryDocument(产品名称,测试)
 

解决方案

使用的coll.update方法。例如以设置一个字段的值

 昏暗的客户端=新MongoClient()
昏暗DB = client.GetServer()。GetDatabase(测试)
昏暗的科尔= db.GetCollection(vbtest)
昏暗productQuery = Query.EQ(产品名称,测试)
昏暗updateStmt = Update.Set(成本,3000)
coll.Update(productQuery,updateStmt)
 

上的方法的详细信息可以在 http://api.mongodb.org/找到CSHARP / 1.8.1 / 。此外,我会建议通过教​​程将在 http://docs.mongodb.org/ecosystem/drivers / CSHARP / 。该例子是在C#中,虽然

I am having problems updating a document in MongoDB using VB.NET & the C# Driver.

I have code returning the document I wish to update but I'm not sure of the syntax to continue

Imports MongoDB.Bson
Imports MongoDB.Driver
Imports MongoDB.Driver.Builders

Dim mongo As MongoServer = MongoServer.Create()
mongo.Connect()
Dim db = mongo.GetDatabase("database")
Dim stock = db.GetCollection(Of BsonDocument)("stock")

Dim getDocument = New QueryDocument("productName", "test")

解决方案

Use the coll.update method. e.g. to set the value of a field

Dim client = New MongoClient()
Dim db = client.GetServer().GetDatabase("test")
Dim coll = db.GetCollection("vbtest")
Dim productQuery = Query.EQ("productName", "test")
Dim updateStmt = Update.Set("cost", 3000)
coll.Update(productQuery, updateStmt)

More information on the methods can be found at http://api.mongodb.org/csharp/1.8.1/. Also I would recommend going through the tutorials at http://docs.mongodb.org/ecosystem/drivers/csharp/. The examples are in C# though

这篇关于更新MongoDB的文档在VB.NET与C#驱动程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆