Remove an item from the list in MONGO with the C # driver

Source: Internet
Author: User

The structure stored in MongoDB is as follows:

public class Questioninfo
{
public int _id {get; set;}//Question ID
Public list<questionsameinfo> samequestions {get; set;}//A set of questions similar to the participle of the topic
Public list<questionsameinfo> samebody {get; set;}//Set of questions similar to the text of the question
public int hasimg {get; set;}//whether there is a picture, 1 is yes, 0 is no
public string Ways {get; set;}//parsing
public int Waysize {get; set;}//Length of resolution
public string Bodymd {set; get;}
}

public class Questionsameinfo
{
public int _id {get; set;}//Question ID
Public double same {get; set;}//Similarity
public int Size {get; set;}//Text length
}

If the structure of MongoDB as shown above, known as the _id of a problem and samequestions in the _id of an item, want to delete an item in samequestions based on these two IDs.

If the _id of the test is the _id of an item in Sid,samequestion, you can write the following code:

var helper = new MongoHelper2 (conn,table);
var query=query.eq ("_id", sid);

var update=update.pull ("Samequestions", Query.eq ("_id", mid));

var result = Helper. Updateone (query, update);

Remove an item from the list in MONGO with the C # driver

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.