Addition, deletion, query and modification operations of MongoDB database

This article is a little note on the study of mongodb. It mainly introduces the simplest addition, deletion and modification operations. Beginners, looking at the API, if there is any mistake, I hope you can correct me: (using the official driver) The addition operation is the easiest, just construct bsonDcument and insert it: Method 1, direct construction: MongoServer dbserver = new MongoClient(connectionStr).GetServer();       MongoDatabase db = dbserver.GetDatabase(dbName); MongoCollection collection = db.GetCollection(collectionName); dbserver.Connect(); BsonDocument doc = new BsonDocument(); doc[“Age”] = Int32.Parse(txt_Age.Text); Doc[“Name”] = txt_Name.Text; doc[“Num”] = txt_Num.Text; doc[“Introduction”] = txt_Introduction.Text; Collection.Insert(doc); Method 2, through entity construction: 1 var student = new Student 2 { 3 Age = Int32.Parse(txt_Age.Text), 4 Name = txt_Name.Text, 5 Num = txt_Num.Text, 6 Introduction = txt_Introduction.Text 7 }; 8 9 collection.Insert(student); The key is to construct the deletion condition, and find the signature of the Remove method through the api: public virtual WriteConcernResult Remove(IMongoQuery query); I saw a lot of ways to write BsonDocument objects in Remove on the Internet, but I checked the source code and found that bsonDocument does not implement the IMongoQuery interface at all. The interface is implemented by a class called QueryDocument, and QueryDocument also inherits the BsonDocument object. And there are…

Contact Us

Contact us

181-3619-1160

Online consultation: QQ交谈

E-mail: 34331943@QQ.com

Working hours: Monday to Friday, 9:00-17:30, holidays off

Follow wechat
Scan wechat and follow us

Scan wechat and follow us

Follow Weibo
Back to top
首页
微信
电话
搜索